# HG changeset patch # User Mychaela Falconia # Date 1665614731 28800 # Node ID bfa9f0c0f0ac859520dc5ee4f234a9faed6ca412 # Parent 83022d40807126ed27e07ee88958b3bac2e76526 sip-out: handle incoming BYE as UAS diff -r 83022d408071 -r bfa9f0c0f0ac sip-out/Makefile --- a/sip-out/Makefile Wed Oct 12 13:44:16 2022 -0800 +++ b/sip-out/Makefile Wed Oct 12 14:45:31 2022 -0800 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 PROG= themwi-sip-out -OBJS= call_clear.o call_list.o call_setup.o disconnect.o invite.o main.o \ - mgw_ops.o mgw_resp.o mgw_sock.o mncc_sig_in.o mncc_sig_out.o \ +OBJS= bye_in.o call_clear.o call_list.o call_setup.o disconnect.o invite.o \ + main.o mgw_ops.o mgw_resp.o mgw_sock.o mncc_sig_in.o mncc_sig_out.o \ mncc_sock.o readconf.o retrans.o shutdown.o sip_log.o sip_uas.o \ sip_udp.o uac_out.o uac_resp.o LIBS= ../liboutrt/liboutrt.a ../libsip/libsip.a ../libutil/libutil.a diff -r 83022d408071 -r bfa9f0c0f0ac sip-out/bye_in.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sip-out/bye_in.c Wed Oct 12 14:45:31 2022 -0800 @@ -0,0 +1,108 @@ +/* + * Here we handle incoming BYE requests in the UAS role. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../include/gsm48_const.h" +#include "../include/out_routes.h" +#include "../libsip/parse.h" +#include "../libsip/uas_basic.h" +#include "../libsip/out_msg.h" +#include "call.h" + +extern struct call *find_call_by_sip_id(); + +extern unsigned sip_linger_gotbye; +extern unsigned sip_linger_response_err; + +static void +bye_found_call(req, ess, sin, call) + struct sip_pkt_rx *req; + struct uas_parse_hdrs *ess; + struct sockaddr_in *sin; + struct call *call; +{ + struct sip_msg_out resp; + int rc; + + switch (call->sip_state) { + case SIP_STATE_INV_SENT: + case SIP_STATE_100_RCVD: + case SIP_STATE_CONNECTED: + call->overall_state = OVERALL_STATE_TEARDOWN; + disconnect_mncc(call, GSM48_CAUSE_LOC_NET_BEYOND, + 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_CANCEL_SENT: + case SIP_STATE_BYE_SENT: + call->sip_state = SIP_STATE_ENDED; + sip_mark_end_time(call, sip_linger_gotbye); + break; + case SIP_STATE_ACCEPT_100: + case SIP_STATE_ACCEPT_200: + case SIP_STATE_ENDED: + break; + case SIP_STATE_MSG_SIZE_ERR: + return; + default: + syslog(LOG_CRIT, + "FATAL: invalid SIP state 0x%x on incoming BYE", + call->sip_state); + exit(1); + } + /* send 200 response to BYE */ + start_response_out_msg(&resp, "200 OK"); + rc = add_resp_basic_headers(&resp, ess, req->req_method); + if (rc < 0) { + syslog(LOG_ERR, "msg size error responding to BYE"); + call->sip_state = SIP_STATE_MSG_SIZE_ERR; + sip_mark_end_time(call, sip_linger_response_err); + return; + } + out_msg_finish(&resp); + sip_tx_packet(&resp, sin); +} + +static void +bye_unknown_call(req, ess, sin) + struct sip_pkt_rx *req; + struct uas_parse_hdrs *ess; + struct sockaddr_in *sin; +{ + struct sip_msg_out resp; + int rc; + + start_response_out_msg(&resp, "481 Call-ID not found"); + rc = add_resp_basic_headers(&resp, ess, req->req_method); + if (rc < 0) + return; + out_msg_finish(&resp); + sip_tx_packet(&resp, sin); +} + +void +handle_bye_req(req, ess, sin) + struct sip_pkt_rx *req; + struct uas_parse_hdrs *ess; + struct sockaddr_in *sin; +{ + struct call *call; + + call = find_call_by_sip_id(ess->call_id); + if (call) + bye_found_call(req, ess, sin, call); + else + bye_unknown_call(req, ess, sin); +} diff -r 83022d408071 -r bfa9f0c0f0ac sip-out/call.h --- a/sip-out/call.h Wed Oct 12 13:44:16 2022 -0800 +++ b/sip-out/call.h Wed Oct 12 14:45:31 2022 -0800 @@ -76,6 +76,7 @@ #define SIP_STATE_ACCEPT_100 6 #define SIP_STATE_ACCEPT_200 7 #define SIP_STATE_ENDED 8 +#define SIP_STATE_MSG_SIZE_ERR 9 #define MGW_STATE_NO_EXIST 0 #define MGW_STATE_ALLOCATED 1 diff -r 83022d408071 -r bfa9f0c0f0ac sip-out/call_list.c --- a/sip-out/call_list.c Wed Oct 12 13:44:16 2022 -0800 +++ b/sip-out/call_list.c Wed Oct 12 14:45:31 2022 -0800 @@ -65,6 +65,7 @@ case SIP_STATE_ACCEPT_100: case SIP_STATE_ACCEPT_200: case SIP_STATE_ENDED: + case SIP_STATE_MSG_SIZE_ERR: if (call->overall_state != OVERALL_STATE_SIP_FINISH) continue; if (got_dead_sip) { diff -r 83022d408071 -r bfa9f0c0f0ac sip-out/invite.c --- a/sip-out/invite.c Wed Oct 12 13:44:16 2022 -0800 +++ b/sip-out/invite.c Wed Oct 12 14:45:31 2022 -0800 @@ -152,7 +152,7 @@ disconnect_mncc(call, GSM48_CAUSE_LOC_PRN_S_LU, GSM48_CC_CAUSE_DEST_OOO); disconnect_tmgw(call); - call->sip_state = SIP_STATE_ENDED; + call->sip_state = SIP_STATE_MSG_SIZE_ERR; sip_mark_end_time(call, sip_linger_response_err); return; } @@ -212,7 +212,7 @@ syslog(LOG_CRIT, "ACK to %03u response exceeds msg size!", msg->status_code); - call->sip_state = SIP_STATE_ENDED; + call->sip_state = SIP_STATE_MSG_SIZE_ERR; sip_mark_end_time(call, sip_linger_response_err); return; } @@ -221,6 +221,7 @@ initiate_bye(call); return; case SIP_STATE_ENDED: + case SIP_STATE_MSG_SIZE_ERR: return; default: syslog(LOG_CRIT, @@ -315,6 +316,8 @@ { int rc; + if (call->sip_state == SIP_STATE_MSG_SIZE_ERR) + return; rc = send_ack(call, tag, sin); if (rc < 0) syslog(LOG_CRIT, "ACK to %03u response exceeds msg size!",