# HG changeset patch # User Mychaela Falconia # Date 1664411533 28800 # Node ID 9b87894704eb2c390b9cc2535730ac144b380007 # Parent 0d6435808bcd7b154df97cd91ec6da2246c24158 sip-in: first step toward final call clearing diff -r 0d6435808bcd -r 9b87894704eb sip-in/Makefile --- a/sip-in/Makefile Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/Makefile Wed Sep 28 16:32:13 2022 -0800 @@ -1,9 +1,10 @@ CC= gcc CFLAGS= -O2 PROG= themwi-sip-in -OBJS= bye_in.o bye_out.o call_list.o call_setup.o cancel.o disconnect.o \ - invite.o main.o mgw_ops.o mgw_sock.o mncc_handle.o mncc_sock.o prack.o \ - readconf.o retrans.o shutdown.o sip_ack.o sip_log.o sip_uas.o sip_udp.o +OBJS= bye_in.o bye_out.o call_clear.o call_list.o call_setup.o cancel.o \ + disconnect.o invite.o main.o mgw_ops.o mgw_sock.o mncc_handle.o \ + mncc_sock.o prack.o readconf.o retrans.o shutdown.o sip_ack.o sip_log.o\ + sip_uas.o sip_udp.o LIBS= ../libnumdb/libnumdb.a ../libsip/libsip.a ../libutil/libutil.a INSTBIN=/usr/local/bin diff -r 0d6435808bcd -r 9b87894704eb sip-in/bye_in.c --- a/sip-in/bye_in.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/bye_in.c Wed Sep 28 16:32:13 2022 -0800 @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -19,6 +20,9 @@ extern struct call *find_call_by_sip_id(); +extern unsigned sip_linger_gotbye; +extern unsigned sip_linger_error; + void handle_sip_bye(req, ess, sin) struct sip_pkt_rx *req; @@ -58,9 +62,11 @@ GSM48_CC_CAUSE_NORM_CALL_CLEAR); disconnect_tmgw(call); call->sip_state = SIP_STATE_ENDED; + sip_mark_end_time(call, sip_linger_gotbye); break; case SIP_STATE_BYE_SENT: call->sip_state = SIP_STATE_ENDED; + sip_mark_end_time(call, sip_linger_gotbye); break; case SIP_STATE_INVITE_ERR: case SIP_STATE_ENDED: @@ -74,6 +80,7 @@ if (rc < 0) { msg_size_err: syslog(LOG_ERR, "BYE 200 response length exceeded"); call->sip_state = SIP_STATE_MSG_SIZE_ERR; + sip_mark_end_time(call, sip_linger_error); return; } rc = out_msg_add_header(&resp, "To", call->invite_to); diff -r 0d6435808bcd -r 9b87894704eb sip-in/bye_out.c --- a/sip-in/bye_out.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/bye_out.c Wed Sep 28 16:32:13 2022 -0800 @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,8 @@ extern struct in_addr sip_bind_ip; extern unsigned sip_bind_port; extern unsigned max_forwards; +extern unsigned sip_linger_acked; +extern unsigned sip_linger_error; fill_bye_out_msg(msg, call) struct sip_msg_out *msg; @@ -107,6 +110,11 @@ } if (msg->status_code < 200) return; - if (call->sip_state == SIP_STATE_BYE_SENT) + if (call->sip_state == SIP_STATE_BYE_SENT) { call->sip_state = SIP_STATE_ENDED; + if (msg->status_code <= 299) + sip_mark_end_time(call, sip_linger_acked); + else + sip_mark_end_time(call, sip_linger_error); + } } diff -r 0d6435808bcd -r 9b87894704eb sip-in/call.h --- a/sip-in/call.h Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/call.h Wed Sep 28 16:32:13 2022 -0800 @@ -40,6 +40,7 @@ uint32_t mncc_callref; char invite_fail[80]; unsigned sip_tx_count; + time_t sip_clear_time; }; #define OVERALL_STATE_CRCX 1 diff -r 0d6435808bcd -r 9b87894704eb sip-in/call_clear.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sip-in/call_clear.c Wed Sep 28 16:32:13 2022 -0800 @@ -0,0 +1,28 @@ +/* + * In this module we implement final clearing of calls, i.e., freeing + * of struct call, and all preliminary steps that need to happen + * toward this ultimate end state. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "call.h" + +extern struct call *call_list; +extern struct timeval cur_event_time; + +void +sip_mark_end_time(call, linger) + struct call *call; + unsigned linger; +{ + call->sip_clear_time = cur_event_time.tv_sec + linger; +} diff -r 0d6435808bcd -r 9b87894704eb sip-in/call_list.c --- a/sip-in/call_list.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/call_list.c Wed Sep 28 16:32:13 2022 -0800 @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff -r 0d6435808bcd -r 9b87894704eb sip-in/call_setup.c --- a/sip-in/call_setup.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/call_setup.c Wed Sep 28 16:32:13 2022 -0800 @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff -r 0d6435808bcd -r 9b87894704eb sip-in/cancel.c --- a/sip-in/cancel.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/cancel.c Wed Sep 28 16:32:13 2022 -0800 @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff -r 0d6435808bcd -r 9b87894704eb sip-in/disconnect.c --- a/sip-in/disconnect.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/disconnect.c Wed Sep 28 16:32:13 2022 -0800 @@ -4,6 +4,7 @@ #include #include +#include #include #include #include diff -r 0d6435808bcd -r 9b87894704eb sip-in/invite.c --- a/sip-in/invite.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/invite.c Wed Sep 28 16:32:13 2022 -0800 @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -26,6 +27,7 @@ extern int cfg_use_100rel; extern int cfg_force_pcma; extern struct call *call_list; +extern unsigned sip_linger_error; extern struct call *find_call_by_sip_id(); extern char *get_single_header(); @@ -408,6 +410,7 @@ disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU, GSM48_CC_CAUSE_INTERWORKING); disconnect_tmgw(call); + sip_mark_end_time(call, sip_linger_error); /* TODO: transition from TEARDOWN to DEAD_SIP */ return; } @@ -443,6 +446,7 @@ disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU, GSM48_CC_CAUSE_INTERWORKING); disconnect_tmgw(call); + sip_mark_end_time(call, sip_linger_error); /* TODO: transition from TEARDOWN to DEAD_SIP */ return; } @@ -463,6 +467,7 @@ if (rc < 0) { syslog(LOG_ERR, "INVITE late error response length exceeded"); call->sip_state = SIP_STATE_MSG_SIZE_ERR; + sip_mark_end_time(call, sip_linger_error); /* TODO: transition from TEARDOWN to DEAD_SIP */ return; } diff -r 0d6435808bcd -r 9b87894704eb sip-in/mgw_ops.c --- a/sip-in/mgw_ops.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/mgw_ops.c Wed Sep 28 16:32:13 2022 -0800 @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff -r 0d6435808bcd -r 9b87894704eb sip-in/mncc_handle.c --- a/sip-in/mncc_handle.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/mncc_handle.c Wed Sep 28 16:32:13 2022 -0800 @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff -r 0d6435808bcd -r 9b87894704eb sip-in/prack.c --- a/sip-in/prack.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/prack.c Wed Sep 28 16:32:13 2022 -0800 @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -22,6 +23,8 @@ extern char *get_single_header(); extern struct call *find_call_by_sip_id(); +extern unsigned sip_linger_error; + void handle_sip_prack(req, ess, sin) struct sip_pkt_rx *req; @@ -90,6 +93,7 @@ disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU, GSM48_CC_CAUSE_INTERWORKING); disconnect_tmgw(call); + sip_mark_end_time(call, sip_linger_error); /* TODO: transition from TEARDOWN to DEAD_SIP */ return; } diff -r 0d6435808bcd -r 9b87894704eb sip-in/readconf.c --- a/sip-in/readconf.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/readconf.c Wed Sep 28 16:32:13 2022 -0800 @@ -21,6 +21,9 @@ unsigned cfg_retrans_timeout = 500; unsigned cfg_retrans_count = 10; unsigned max_forwards = 70; +unsigned sip_linger_acked = 5; +unsigned sip_linger_gotbye = 30; +unsigned sip_linger_error = 180; static char config_file_pathname[] = "/var/gsm/themwi-sip-in.cfg"; @@ -174,6 +177,18 @@ handler = handle_retrans_conf; var = (void *) 0; set_id = 0; + } else if (!strcmp(kw, "sip-linger-acked")) { + handler = handle_num; + var = &sip_linger_acked; + set_id = 0; + } else if (!strcmp(kw, "sip-linger-got-bye")) { + handler = handle_num; + var = &sip_linger_gotbye; + set_id = 0; + } else if (!strcmp(kw, "sip-linger-error")) { + handler = handle_num; + var = &sip_linger_error; + set_id = 0; } else if (!strcmp(kw, "max-forwards")) { handler = &handle_num; var = &max_forwards; diff -r 0d6435808bcd -r 9b87894704eb sip-in/retrans.c --- a/sip-in/retrans.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/retrans.c Wed Sep 28 16:32:13 2022 -0800 @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include "call.h" extern unsigned cfg_retrans_count; +extern unsigned sip_linger_error; extern struct call *call_list; void @@ -66,16 +68,20 @@ out_msg_finish(&msg); sip_tx_packet(&msg, &call->udp_sin); call->sip_tx_count++; - } else + } else { call->sip_state = SIP_STATE_ENDED; + sip_mark_end_time(call, sip_linger_error); + } break; case SIP_STATE_BYE_SENT: if (call->sip_tx_count < cfg_retrans_count) { fill_bye_out_msg(&msg, call); sip_tx_packet(&msg, &call->udp_sin); call->sip_tx_count++; - } else + } else { call->sip_state = SIP_STATE_ENDED; + sip_mark_end_time(call, sip_linger_error); + } break; } } diff -r 0d6435808bcd -r 9b87894704eb sip-in/shutdown.c --- a/sip-in/shutdown.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/shutdown.c Wed Sep 28 16:32:13 2022 -0800 @@ -10,6 +10,7 @@ #include #include +#include #include #include #include diff -r 0d6435808bcd -r 9b87894704eb sip-in/sip_ack.c --- a/sip-in/sip_ack.c Wed Sep 28 14:29:10 2022 -0800 +++ b/sip-in/sip_ack.c Wed Sep 28 16:32:13 2022 -0800 @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,8 @@ extern struct call *find_call_by_sip_id(); +extern unsigned sip_linger_acked; + void handle_sip_ack(req, ess, sin) struct sip_pkt_rx *req; @@ -51,6 +54,7 @@ break; case SIP_STATE_INVITE_ERR: call->sip_state = SIP_STATE_ENDED; + sip_mark_end_time(call, sip_linger_acked); break; } }