Asterisk - The Open Source Telephony Project  GIT-master-4a4f1a5
Data Structures | Macros | Enumerations | Functions | Variables
chan_sip.c File Reference

Implementation of Session Initiation Protocol. More...

#include "asterisk.h"
#include <signal.h>
#include <regex.h>
#include <inttypes.h>
#include "asterisk/network.h"
#include "asterisk/paths.h"
#include "asterisk/lock.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/udptl.h"
#include "asterisk/acl.h"
#include "asterisk/manager.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
#include "asterisk/musiconhold.h"
#include "asterisk/dsp.h"
#include "asterisk/pickup.h"
#include "asterisk/parking.h"
#include "asterisk/srv.h"
#include "asterisk/astdb.h"
#include "asterisk/causes.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
#include "asterisk/astobj2.h"
#include "asterisk/dnsmgr.h"
#include "asterisk/devicestate.h"
#include "asterisk/netsock2.h"
#include "asterisk/localtime.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/threadstorage.h"
#include "asterisk/translate.h"
#include "asterisk/ast_version.h"
#include "asterisk/aoc.h"
#include "asterisk/message.h"
#include "sip/include/sip.h"
#include "sip/include/globals.h"
#include "sip/include/config_parser.h"
#include "sip/include/reqresp_parser.h"
#include "sip/include/sip_utils.h"
#include "asterisk/sdp_srtp.h"
#include "asterisk/ccss.h"
#include "asterisk/xml.h"
#include "sip/include/dialog.h"
#include "sip/include/dialplan_functions.h"
#include "sip/include/security_events.h"
#include "sip/include/route.h"
#include "asterisk/sip_api.h"
#include "asterisk/mwi.h"
#include "asterisk/bridge.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_endpoints.h"
#include "asterisk/stasis_system.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/features_config.h"
#include "asterisk/http_websocket.h"
#include "asterisk/format_cache.h"
#include "asterisk/linkedlists.h"

Go to the source code of this file.

Data Structures

struct  blind_transfer_cb_data
 
struct  cfalias
 Structure for conversion between compressed SIP and "normal" SIP headers. More...
 
struct  cfsip_methods
 The core structure to setup dialogs. We parse incoming messages by using structure and then route the messages according to the type. More...
 
struct  cfsubscription_types
 Subscription types that we support. We support. More...
 
struct  domain_list
 
struct  epa_static_data_list
 
struct  event_state_compositor
 The Event State Compositors. More...
 
struct  invstate2stringtable
 Readable descriptions of device states. More...
 
struct  match_req_args
 arguments used for Request/Response to matching More...
 
struct  mwi_subscription_data
 
struct  reregister_data
 
struct  show_peers_context
 Used in the sip_show_peers functions to pass parameters. More...
 
struct  sip_history_head
 
struct  sip_reasons
 Diversion header reasons. More...
 
struct  sip_scheddestroy_data
 
struct  state_notify_data
 

Macros

#define append_history(p, event, fmt, args...)   append_history_full(p, "%-15s " fmt, event, ## args)
 Append to SIP dialog history. More...
 
#define BOGUS_PEER_MD5SECRET   "intentionally_invalid_md5_string"
 We can recognize the bogus peer by this invalid MD5 hash. More...
 
#define check_request_transport(peer, tmpl)
 generic function for determining if a correct transport is being used to contact a peer More...
 
#define CONTAINER_UNLINK(container, obj, tag)
 Unlink the given object from the container and return TRUE if it was in the container. More...
 
#define find_call(req, addr, intended_method)    __find_call(req, addr, intended_method, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 
#define FORMAT   "%-25.25s %-15.15s %-15.15s \n"
 
#define FORMAT   "%-47.47s %-9.9s %-6.6s\n"
 
#define FORMAT   "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n"
 
#define FORMAT   "%-40.40s %-20.20s %-16.16s\n"
 
#define FORMAT   "%-39.39s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n"
 
#define FORMAT   "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf\n"
 
#define FORMAT   "%-30.30s %-12.12s %-10.10s %-10.10s\n"
 
#define FORMAT   "%-15.15s %-15.15s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s %-10.10s\n"
 
#define FORMAT2   "%-25.25s %-15.15s %-15.15s \n"
 
#define FORMAT2   "%-47.47s %9.9s %6.6s\n"
 
#define FORMAT2   "%-39.39s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n"
 
#define FORMAT2   "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n"
 
#define FORMAT2   "%-15.15s %-15.15s %-15.15s %-15.15s %-7.7s %-15.15s %-10.10s %-10.10s\n"
 
#define FORMAT3   "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6s\n"
 
#define FORMAT4   "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6d\n"
 
#define peer_in_destruction(peer)   (ao2_ref(peer, 0) == 0)
 
#define PEERS_FORMAT2   "%-25.25s %-39.39s %-3.3s %-10.10s %-10.10s %-3.3s %-8s %-11s %-32.32s %s\n"
 
#define REMOVE_MAILBOX_WITH_LOCKED_PEER(__peer)
 
#define sip_pvt_lock(x)   ao2_lock(x)
 
#define sip_pvt_trylock(x)   ao2_trylock(x)
 
#define sip_pvt_unlock(x)   ao2_unlock(x)
 
#define SIP_TRANSPORT_STR_BUFSIZE   128
 Size of the SIP transport buffer. More...
 
#define SIPHEADER   256
 
#define UNLINK(element, head, prev)
 

Enumerations

enum  match_req_res { SIP_REQ_MATCH , SIP_REQ_NOT_MATCH , SIP_REQ_LOOP_DETECTED , SIP_REQ_FORKED }
 
enum  message_integrity { MESSAGE_INVALID , MESSAGE_FRAGMENT , MESSAGE_FRAGMENT_COMPLETE , MESSAGE_COMPLETE }
 Indication of a TCP message's integrity. More...
 
enum  peer_unlink_flag_t { SIP_PEERS_MARKED , SIP_PEERS_ALL }
 
enum  sip_media_fds {
  SIP_AUDIO_RTP_FD , SIP_AUDIO_RTCP_FD , SIP_VIDEO_RTP_FD , SIP_VIDEO_RTCP_FD ,
  SIP_TEXT_RTP_FD , SIP_UDPTL_FD
}
 

Functions

static int __cleanup_registration (const void *data)
 
static int __dialog_unlink_sched_items (const void *data)
 
static struct sip_pvt__find_call (struct sip_request *req, struct ast_sockaddr *addr, const int intended_method, const char *file, int line, const char *func)
 find or create a dialog structure for an incoming SIP message. Connect incoming SIP message to current dialog or create new dialog structure Returns a reference to the sip_pvt object, remember to give it back once done. Called by handle_request_do More...
 
static const char * __get_header (const struct sip_request *req, const char *name, int *start)
 
static void __init_sip_content_buf (void)
 
static void __init_sip_transport_str_buf (void)
 A per-thread buffer for transport to string conversion. More...
 
static void __init_ts_temp_pvt (void)
 A per-thread temporary pvt structure. More...
 
static void __reg_module (void)
 
static int __sched_check_pendings (const void *data)
 
static int __set_address_from_contact (const char *fullcontact, struct ast_sockaddr *addr, int tcp)
 
static int __shutdown_mwi_subscription (const void *data)
 
int __sip_ack (struct sip_pvt *p, uint32_t seqno, int resp, int sipmethod)
 Acknowledges receipt of a packet and stops retransmission called with p locked. More...
 
struct sip_pvt__sip_alloc (ast_string_field callid, struct ast_sockaddr *addr, int useglobal_nat, const int intended_method, struct sip_request *req, ast_callid logger_callid, const char *file, int line, const char *func)
 Allocate sip_pvt structure, set defaults and link in the container. Returns a reference to the object so whoever uses it later must remember to release the reference. More...
 
static int __sip_autodestruct (const void *data)
 Kill a SIP dialog (called only by the scheduler) The scheduler has a reference to this dialog when p->autokillid != -1, and we are called using that reference. So if the event is not rescheduled, we need to call dialog_unref(). More...
 
static int __sip_cancel_destroy (const void *data)
 
static int __sip_do_register (struct sip_registry *r)
 Register with SIP proxy. More...
 
void __sip_pretend_ack (struct sip_pvt *p)
 Pretend to ack all packets called with p locked. More...
 
static int __sip_reliable_xmit (struct sip_pvt *p, uint32_t seqno, int resp, struct ast_str *data, int fatal, int sipmethod)
 
static int __sip_scheddestroy (const void *data)
 
int __sip_semi_ack (struct sip_pvt *p, uint32_t seqno, int resp, int sipmethod)
 Acks receipt of packet, keep it around (used for provisional responses) More...
 
static int __sip_subscribe_mwi_do (struct sip_subscription_mwi *mwi)
 Actually setup an MWI subscription or resubscribe. More...
 
static int __sip_xmit (struct sip_pvt *p, struct ast_str *data)
 
static int __start_mwi_subscription (const void *data)
 
static int __start_register_timeout (const void *data)
 
static int __start_reregister_timeout (const void *data)
 
static int __start_session_timer (const void *data)
 
static int __start_t38_abort_timer (const void *data)
 
static int __stop_provisional_keepalive (const void *data)
 
static int __stop_register_timeout (const void *data)
 
static int __stop_reinvite_retry (const void *data)
 
static int __stop_reinviteid (const void *data)
 
static int __stop_retrans_pkt (const void *data)
 
static int __stop_session_timer (const void *data)
 
static int __stop_t38_abort_timer (const void *data)
 
static int __transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable)
 Base transmit response function. More...
 
static void __unreg_module (void)
 
static int __update_provisional_keepalive (const void *data)
 
static int __update_provisional_keepalive_full (struct sip_pvt *pvt, int with_sdp)
 
static int __update_provisional_keepalive_with_sdp (const void *data)
 
static char * _sip_qualify_peer (int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
 Send qualify message to peer from cli or manager. Mostly for debugging. More...
 
static char * _sip_show_peer (int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[])
 Show one peer in detail (main function) More...
 
static char * _sip_show_peers (int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[])
 Execute sip show peers command. More...
 
static struct sip_peer_sip_show_peers_one (int fd, struct mansession *s, struct show_peers_context *cont, struct sip_peer *peer)
 Emit informations for one peer during sip show peers command. More...
 
static void * _sip_tcp_helper_thread (struct ast_tcptls_session_instance *tcptls_session)
 SIP TCP thread management function This function reads from the socket, parses the packet into a request. More...
 
static void acl_change_event_stasis_unsubscribe (void)
 
static void acl_change_stasis_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void acl_change_stasis_subscribe (void)
 
static void add_blank (struct sip_request *req)
 add a blank line if no body More...
 
static void add_cc_call_info_to_response (struct sip_pvt *p, struct sip_request *resp)
 
static void add_codec_to_sdp (const struct sip_pvt *p, struct ast_format *format, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size, int *max_packet_size)
 Add codec offer to SDP offer/answer body in INVITE or 200 OK. More...
 
static int add_content (struct sip_request *req, const char *line)
 Add content (not header) to SIP message. More...
 
static void add_date (struct sip_request *req)
 Add date header to SIP message. More...
 
static int add_digit (struct sip_request *req, char digit, unsigned int duration, int mode)
 Add DTMF INFO tone to sip message Mode = 0 for application/dtmf-relay (Cisco) 1 for application/dtmf. More...
 
static void add_diversion (struct sip_request *req, struct sip_pvt *pvt)
 Add "Diversion" header to outgoing message. More...
 
static void add_dtls_to_sdp (struct ast_rtp_instance *instance, struct ast_str **a_buf)
 Add DTLS attributes to SDP. More...
 
static void add_expires (struct sip_request *req, int expires)
 Add Expires header to SIP message. More...
 
static int add_header (struct sip_request *req, const char *var, const char *value)
 Add header to SIP message. More...
 
static void add_ice_to_sdp (struct ast_rtp_instance *instance, struct ast_str **a_buf)
 Add ICE attributes to SDP. More...
 
static int add_max_forwards (struct sip_pvt *dialog, struct sip_request *req)
 Add 'Max-Forwards' header to SIP message. More...
 
static void add_msg_header (struct sip_pvt *pvt, const char *hdr_name, const char *hdr_value)
 
static void add_noncodec_to_sdp (const struct sip_pvt *p, int format, struct ast_str **m_buf, struct ast_str **a_buf, int debug)
 Add RFC 2833 DTMF offer to SDP. More...
 
static void add_peer_mailboxes (struct sip_peer *peer, const char *value)
 
static void add_peer_mwi_subs (struct sip_peer *peer)
 
static void add_realm_authentication (struct sip_auth_container **credentials, const char *configuration, int lineno)
 
static void add_required_respheader (struct sip_request *req)
 
static void add_route (struct sip_request *req, struct sip_route *route, int skip)
 Add route header into request per learned route. More...
 
static int add_rpid (struct sip_request *req, struct sip_pvt *p)
 Add Remote-Party-ID header to SIP message. More...
 
static enum sip_result add_sdp (struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38)
 Add Session Description Protocol message. More...
 
static int add_sip_domain (const char *domain, const enum domain_mode mode, const char *context)
 Add SIP domain to list of domains we are responsible for. More...
 
static int add_supported (struct sip_pvt *pvt, struct sip_request *req)
 Add "Supported" header to sip message. Since some options may be disabled in the config, the sip_pvt must be inspected to determine what is supported for this dialog. More...
 
static void add_tcodec_to_sdp (const struct sip_pvt *p, struct ast_format *format, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size)
 Add text codec offer to SDP offer/answer body in INVITE or 200 OK. More...
 
static int add_text (struct sip_request *req, struct sip_pvt *p)
 Add text body to SIP message. More...
 
static struct ast_variableadd_var (const char *buf, struct ast_variable *list)
 implement the setvar config line More...
 
static void add_vcodec_to_sdp (const struct sip_pvt *p, struct ast_format *format, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size)
 Add video codec offer to SDP offer/answer body in INVITE or 200 OK. More...
 
static int add_vidupdate (struct sip_request *req)
 add XML encoded media control with update More...
 
static int allow_notify_user_presence (struct sip_pvt *p)
 
static const char * allowoverlap2str (int mode)
 Convert AllowOverlap setting to printable string. More...
 
static AO2_GLOBAL_OBJ_STATIC (g_bogus_peer)
 A bogus peer, to be used when authentication should fail. More...
 
static void append_history_full (struct sip_pvt *p, const char *fmt,...)
 Append to SIP dialog history with arg list
More...
 
static void append_history_va (struct sip_pvt *p, const char *fmt, va_list ap)
 Append to SIP dialog history with arg list
More...
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static void ast_sip_ouraddrfor (const struct ast_sockaddr *them, struct ast_sockaddr *us, struct sip_pvt *p)
 NAT fix - decide which IP address to use for Asterisk server? More...
 
static int ast_sockaddr_resolve_first (struct ast_sockaddr *addr, const char *name, int flag)
 Return the first entry from ast_sockaddr_resolve filtered by family of binddaddr. More...
 
static int ast_sockaddr_resolve_first_transport (struct ast_sockaddr *addr, const char *name, int flag, unsigned int transport)
 Return the first entry from ast_sockaddr_resolve filtered by family of binddaddr. More...
 
static int auto_congest (const void *arg)
 Scheduled congestion on a call. Only called by the scheduler, must return the reference when done. More...
 
static const char * autocreatepeer2str (enum autocreatepeer_mode r)
 
static void blind_transfer_cb (struct ast_channel *chan, struct transfer_channel_data *user_data_wrapper, enum ast_transfer_type transfer_type)
 
static int block_msg_header (const char *header_name)
 
static void build_callid_pvt (struct sip_pvt *pvt)
 Build SIP Call-ID value for a non-REGISTER transaction. More...
 
static void build_callid_registry (struct sip_registry *reg, const struct ast_sockaddr *ourip, const char *fromdomain)
 Build SIP Call-ID value for a REGISTER transaction. More...
 
static void build_contact (struct sip_pvt *p, struct sip_request *req, int incoming)
 Build contact header. More...
 
static void build_localtag_registry (struct sip_registry *reg)
 Build SIP From tag value for REGISTER. More...
 
static void build_nonce (struct sip_pvt *p, int forceupdate)
 builds the sip_pvt's nonce field which is used for the authentication challenge. When forceupdate is not set, the nonce is only updated if the current one is stale. In this case, a stalenonce is one which has already received a response, if a nonce has not received a response it is not always necessary or beneficial to create a new one. More...
 
static int build_path (struct sip_pvt *p, struct sip_peer *peer, struct sip_request *req, const char *pathbuf)
 Build route list from Path header RFC 3327 requires that the Path header contains SIP URIs with lr paramter. Thus, we do not care about strict routing SIP routers. More...
 
static struct sip_peerbuild_peer (const char *name, struct ast_variable *v_head, struct ast_variable *alt, int realtime, int devstate_only)
 Build peer from configuration (file or realtime static/dynamic) More...
 
static int build_reply_digest (struct sip_pvt *p, int method, char *digest, int digest_len)
 Build reply digest. More...
 
static void build_route (struct sip_pvt *p, struct sip_request *req, int backwards, int resp)
 Build route list from Record-Route header. More...
 
static void build_via (struct sip_pvt *p)
 Build a Via header for a request. More...
 
static int cb_extensionstate (const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
 Callback for the devicestate notification (SUBSCRIBE) support subsystem. More...
 
static void cb_extensionstate_destroy (int id, void *data)
 
static void cc_epa_destructor (void *data)
 
static int cc_esc_publish_handler (struct sip_pvt *pvt, struct sip_request *req, struct event_state_compositor *esc, struct sip_esc_entry *esc_entry)
 
static void cc_handle_publish_error (struct sip_pvt *pvt, const int resp, struct sip_request *req, struct sip_epa_entry *epa_entry)
 
static void change_callid_pvt (struct sip_pvt *pvt, const char *callid)
 
static void change_hold_state (struct sip_pvt *dialog, struct sip_request *req, int holdstate, int sendonly)
 Change hold state for a call. More...
 
static void change_redirecting_information (struct sip_pvt *p, struct sip_request *req, struct ast_party_redirecting *redirecting, struct ast_set_party_redirecting *update_redirecting, int set_call_forward)
 update redirecting information for a channel based on headers More...
 
static void change_t38_state (struct sip_pvt *p, int state)
 Change the T38 state on a SIP dialog. More...
 
static enum check_auth_result check_auth (struct sip_pvt *p, struct sip_request *req, const char *username, const char *secret, const char *md5secret, int sipmethod, const char *uri, enum xmittype reliable)
 Check user authorization from peer definition Some actions, like REGISTER and INVITEs from peers require authentication (if peer have secret set) More...
 
static void check_for_nat (const struct ast_sockaddr *addr, struct sip_pvt *p)
 Check and see if the requesting UA is likely to be behind a NAT. More...
 
static enum message_integrity check_message_integrity (struct ast_str **request, struct ast_str **overflow)
 Check that a message received over TCP is a full message. More...
 
static enum check_auth_result check_peer_ok (struct sip_pvt *p, char *of, struct sip_request *req, int sipmethod, struct ast_sockaddr *addr, struct sip_peer **authpeer, enum xmittype reliable, char *calleridname, char *uri2)
 Validate device authentication. More...
 
static void check_pendings (struct sip_pvt *p)
 Check pending actions on SIP call. More...
 
static int check_rtp_timeout (struct sip_pvt *dialog, time_t t)
 helper function for the monitoring thread – seems to be called with the assumption that the dialog is locked More...
 
static int check_sip_domain (const char *domain, char *context, size_t len)
 check_sip_domain: Check if domain part of uri is local to our server More...
 
static int check_user (struct sip_pvt *p, struct sip_request *req, int sipmethod, const char *uri, enum xmittype reliable, struct ast_sockaddr *addr)
 Find user If we get a match, this will add a reference pointer to the user object, that needs to be unreferenced. More...
 
static enum check_auth_result check_user_full (struct sip_pvt *p, struct sip_request *req, int sipmethod, const char *uri, enum xmittype reliable, struct ast_sockaddr *addr, struct sip_peer **authpeer)
 Check if matching user or peer is defined Match user on From: user name and peer on IP/port This is used on first invite (not re-invites) and subscribe requests. More...
 
static void check_via (struct sip_pvt *p, const struct sip_request *req)
 check Via: header for hostname, port and rport request/answer More...
 
static void cleanup_all_regs (void)
 
static int cleanup_registration (void *obj, void *arg, int flags)
 
static void cleanup_stale_contexts (char *new, char *old)
 Destroy disused contexts between reloads Only used in reload_config so the code for regcontext doesn't get ugly. More...
 
static void clear_peer_mailboxes (struct sip_peer *peer)
 
static void clear_sip_domains (void)
 Clear our domain list (at reload) More...
 
static char * complete_sip_notify (const char *line, const char *word, int pos, int state)
 Support routine for 'sip notify' CLI. More...
 
static char * complete_sip_peer (const char *word, int state, int flags2)
 Do completion on peer name. More...
 
static char * complete_sip_registered_peer (const char *word, int state, int flags2)
 Do completion on registered peer name. More...
 
static char * complete_sip_show_history (const char *line, const char *word, int pos, int state)
 Support routine for 'sip show history' CLI. More...
 
static char * complete_sip_show_peer (const char *line, const char *word, int pos, int state)
 Support routine for 'sip show peer' CLI. More...
 
static char * complete_sip_show_user (const char *line, const char *word, int pos, int state)
 Support routine for 'sip show user' CLI. More...
 
static char * complete_sip_unregister (const char *line, const char *word, int pos, int state)
 Support routine for 'sip unregister' CLI. More...
 
static char * complete_sip_user (const char *word, int state)
 Do completion on user name. More...
 
static char * complete_sipch (const char *line, const char *word, int pos, int state)
 Support routine for 'sip show channel' and 'sip show history' CLI This is in charge of generating all strings that match a prefix in the given position. As many functions of this kind, each invokation has O(state) time complexity so be careful in using it. More...
 
static void configure_rtcp (struct sip_pvt *p, struct ast_rtp_instance *instance, int which, int remote_rtcp_mux)
 
static int construct_pidf_body (enum sip_cc_publish_state state, char *pidf_body, size_t size, const char *presentity)
 
static int copy_all_header (struct sip_request *req, const struct sip_request *orig, const char *field)
 Copy all headers from one request to another. More...
 
static int copy_header (struct sip_request *req, const struct sip_request *orig, const char *field)
 Copy one header field from one request to another. More...
 
static void copy_request (struct sip_request *dst, const struct sip_request *src)
 copy SIP request (mostly used to save request for responses) More...
 
static void copy_socket_data (struct sip_socket *to_sock, const struct sip_socket *from_sock)
 
static struct ast_variablecopy_vars (struct ast_variable *src)
 duplicate a list of channel variables, More...
 
static int copy_via_headers (struct sip_pvt *p, struct sip_request *req, const struct sip_request *orig, const char *field)
 Copy SIP VIA Headers from the request to the response. More...
 
static int create_addr (struct sip_pvt *dialog, const char *opeer, struct ast_sockaddr *addr, int newdialog)
 create address structure from device name Or, if peer not found, find it in the global DNS returns TRUE (-1) on failure, FALSE on success More...
 
static int create_addr_from_peer (struct sip_pvt *dialog, struct sip_peer *peer)
 Create address structure from peer reference. This function copies data from peer to the dialog, so we don't have to look up the peer again from memory or database during the life time of the dialog. More...
 
static struct sip_epa_entrycreate_epa_entry (const char *const event_package, const char *const destination)
 
static struct sip_esc_entrycreate_esc_entry (struct event_state_compositor *esc, struct sip_request *req, const int expires)
 
static void create_new_sip_etag (struct sip_esc_entry *esc_entry, int is_linked)
 
static char * crypto_get_attrib (struct ast_sdp_srtp *srtp, int dtls_enabled, int default_taglen_32)
 
static int default_sip_port (enum ast_transport type)
 The default sip port for the given transport. More...
 
static void deinit_req (struct sip_request *req)
 Deinitialize SIP response/request. More...
 
static void deprecation_notice (void)
 
static void destroy_association (struct sip_peer *peer)
 Remove registration data from realtime database or AST/DB when registration expires. More...
 
static void destroy_escs (void)
 
static void destroy_mailbox (struct sip_mailbox *mailbox)
 
static void destroy_msg_headers (struct sip_pvt *pvt)
 
static void destroy_realm_authentication (void *obj)
 
static int determine_firstline_parts (struct sip_request *req)
 Parse first line of incoming SIP request. More...
 
static enum sip_publish_type determine_sip_publish_type (struct sip_request *req, const char *const event, const char *const etag, const char *const expires, int *expires_int)
 
static int dialog_checkrtp_cb (void *dialogobj, void *arg, int flags)
 Check RTP Timeout on dialogs. More...
 
static void dialog_clean_rtp (struct sip_pvt *p)
 
static int dialog_cmp_cb (void *obj, void *arg, int flags)
 
static int dialog_dump_func (void *userobj, void *arg, int flags)
 
static int dialog_find_multiple (void *obj, void *arg, int flags)
 
static int dialog_hash_cb (const void *obj, const int flags)
 
static int dialog_initialize_dtls_srtp (const struct sip_pvt *dialog, struct ast_rtp_instance *rtp, struct ast_sdp_srtp **srtp)
 Initialize DTLS-SRTP support on an RTP instance. More...
 
static int dialog_initialize_rtp (struct sip_pvt *dialog)
 Initialize RTP portion of a dialog. More...
 
static int dialog_needdestroy (void *dialogobj, void *arg, int flags)
 Match dialogs that need to be destroyed. More...
 
void dialog_unlink_all (struct sip_pvt *dialog)
 Unlink a dialog from the dialogs container, as well as any other places that it may be currently stored. More...
 
static void disable_dsp_detect (struct sip_pvt *p)
 
static void display_nat_warning (const char *cat, int reason, struct ast_flags *flags)
 
static void do_cancel_destroy (struct sip_pvt *pvt)
 
static void do_dialog_unlink_sched_items (struct sip_pvt *dialog)
 
static int do_magic_pickup (struct ast_channel *channel, const char *extension, const char *context)
 
static int do_message_auth (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void * do_monitor (void *data)
 The SIP monitoring thread. More...
 
static int do_proxy_auth (struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code, int sipmethod, int init)
 Add authentication on outbound SIP packet. More...
 
static int do_register_auth (struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code)
 Authenticate for outbound registration. More...
 
static void do_setnat (struct sip_pvt *p)
 Set nat mode on the various data sockets. More...
 
static void do_stop_session_timer (struct sip_pvt *pvt)
 
static const char * domain_mode_to_text (const enum domain_mode mode)
 Print domain mode to cli. More...
 
static const char * dtmfmode2str (int mode)
 Convert DTMF mode to printable string. More...
 
static void enable_dsp_detect (struct sip_pvt *p)
 
static int esc_cmp_fn (void *obj, void *arg, int flags)
 
static void esc_entry_destructor (void *obj)
 
static int esc_hash_fn (const void *obj, const int flags)
 
static int expire_register (const void *data)
 Expire registration of SIP peer. More...
 
static int extensionstate_update (const char *context, const char *exten, struct state_notify_data *data, struct sip_pvt *p, int force)
 Callback for the devicestate notification (SUBSCRIBE) support subsystem. More...
 
static void extract_host_from_hostport (char **hostport)
 Terminate a host:port at the ':'. More...
 
static void extract_transferrer_headers (const char *prefix, struct ast_channel *peer, const struct sip_request *req)
 
static void extract_uri (struct sip_pvt *p, struct sip_request *req)
 Check Contact: URI of SIP message. More...
 
static const char * faxec2str (int faxec)
 
static int finalize_content (struct sip_request *req)
 Add 'Content-Length' header and content to SIP message. More...
 
static const char * find_alias (const char *name, const char *_default)
 Find compressed SIP alias. More...
 
static int find_by_callid_helper (void *obj, void *arg, int flags)
 
static int find_by_name (void *obj, void *arg, void *data, int flags)
 
static int find_by_notify_uri_helper (void *obj, void *arg, int flags)
 
static int find_by_subscribe_uri_helper (void *obj, void *arg, int flags)
 
const char * find_closing_quote (const char *start, const char *lim)
 Locate closing quote in a string, skipping escaped quotes. optionally with a limit on the search. start must be past the first quote. More...
 
static const char * find_full_alias (const char *name, const char *_default)
 Find full SIP alias. More...
 
static struct sip_authfind_realm_authentication (struct sip_auth_container *credentials, const char *realm)
 
static struct ast_channelfind_ringing_channel (struct ao2_container *device_state_info, struct sip_pvt *p)
 
static int find_sdp (struct sip_request *req)
 Determine whether a SIP message contains an SDP in its body. More...
 
static struct ast_cc_agentfind_sip_cc_agent_by_notify_uri (const char *const uri)
 
static struct ast_cc_agentfind_sip_cc_agent_by_original_callid (struct sip_pvt *pvt)
 
static struct ast_cc_agentfind_sip_cc_agent_by_subscribe_uri (const char *const uri)
 
static int find_sip_method (const char *msg)
 find_sip_method: Find SIP method from header More...
 
static int find_sip_monitor_instance_by_subscription_pvt (void *obj, void *arg, int flags)
 
static int find_sip_monitor_instance_by_suspension_entry (void *obj, void *arg, int flags)
 
static const struct epa_static_datafind_static_data (const char *const event_package)
 
static const struct cfsubscription_typesfind_subscription_type (enum subscriptiontype subtype)
 Find subscription type in array. More...
 
static void forked_invite_init (struct sip_request *req, const char *new_theirtag, struct sip_pvt *original, struct ast_sockaddr *addr)
 This function creates a dialog to handle a forked request. This dialog exists only to properly terminiate the forked request immediately. More...
 
static int func_check_sipdomain (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 Dial plan function to check if domain is local. More...
 
static int func_header_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
 Read SIP header (dialplan function) More...
 
static int func_headers_read2 (struct ast_channel *chan, const char *function, char *data, struct ast_str **buf, ssize_t maxlen)
 Read unique list of SIP headers (dialplan function) More...
 
static int function_sippeer (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 ${SIPPEER()} Dialplan function - reads peer data More...
 
static char * generate_random_string (char *buf, size_t size)
 Generate 32 byte random string for callid's etc. More...
 
static char * generate_uri (struct sip_pvt *pvt, char *buf, size_t size)
 
static int get_address_family_filter (unsigned int transport)
 Helper for dns resolution to filter by address family. More...
 
static int get_also_info (struct sip_pvt *p, struct sip_request *oreq)
 Call transfer support (old way, deprecated by the IETF) More...
 
static int get_cached_mwi (struct sip_peer *peer, int *new, int *old)
 Get cached MWI info. More...
 
static char * get_content (struct sip_request *req)
 Get message body content. More...
 
static char * get_content_line (struct sip_request *req, char *name, char delimiter)
 Get a specific line from the message content. More...
 
static enum sip_get_dest_result get_destination (struct sip_pvt *p, struct sip_request *oreq, int *cc_recall_core_id)
 Find out who the call is for. More...
 
static int get_domain (const char *str, char *domain, int len)
 Extract domain from SIP To/From header. More...
 
static struct event_state_compositorget_esc (const char *const event_package)
 
static struct sip_esc_entryget_esc_entry (const char *entity_tag, struct event_state_compositor *esc)
 
static struct ast_variableget_insecure_variable_from_config (struct ast_config *config)
 
static struct ast_variableget_insecure_variable_from_sippeers (const char *column, const char *value)
 
static struct ast_variableget_insecure_variable_from_sipregs (const char *column, const char *value, struct ast_variable **var)
 
static const char * get_name_from_variable (const struct ast_variable *var)
 
static void get_our_media_address (struct sip_pvt *p, int needvideo, int needtext, struct ast_sockaddr *addr, struct ast_sockaddr *vaddr, struct ast_sockaddr *taddr, struct ast_sockaddr *dest, struct ast_sockaddr *vdest, struct ast_sockaddr *tdest)
 Set all IP media addresses for this call. More...
 
static int get_pai (struct sip_pvt *p, struct sip_request *req)
 Parse the parts of the P-Asserted-Identity header on an incoming packet. Returns 1 if a valid header is found and it is different from the current caller id. More...
 
static int get_rdnis (struct sip_pvt *p, struct sip_request *oreq, char **name, char **number, int *reason_code, char **reason_str)
 Get referring dnis. More...
 
static void get_realm (struct sip_pvt *p, const struct sip_request *req)
 Choose realm based on From header and then To header or use globally configured realm. Realm from From/To header should be listed among served domains in config file: domain=... More...
 
static int get_refer_info (struct sip_pvt *transferer, struct sip_request *outgoing_req)
 Call transfer support (the REFER method) Extracts Refer headers into pvt dialog structure. More...
 
static int get_rpid (struct sip_pvt *p, struct sip_request *oreq)
 Get name, number and presentation from remote party id header, returns true if a valid header was found and it was different from the current caller id. More...
 
static const char * get_sdp_iterate (int *start, struct sip_request *req, const char *name)
 Lookup 'name' in the SDP starting at the 'start' line. Returns the matching line, and 'start' is updated with the next line number. More...
 
static char get_sdp_line (int *start, int stop, struct sip_request *req, const char **value)
 Fetches the next valid SDP line between the 'start' line (inclusive) and the 'stop' line (exclusive). Returns the type ('a', 'c', ...) and matching line in reference 'start' is updated with the next line number. More...
 
static int get_sip_pvt_from_replaces (const char *callid, const char *totag, const char *fromtag, struct sip_pvt **out_pvt, struct ast_channel **out_chan)
 Find a companion dialog based on Replaces information. More...
 
static const char * get_srv_protocol (enum ast_transport t)
 Return protocol string for srv dns query. More...
 
static const char * get_srv_service (enum ast_transport t)
 Return service string for srv dns query. More...
 
static const char * get_transport_list (unsigned int transports)
 Return configuration of transports for a device. More...
 
static const char * get_transport_pvt (struct sip_pvt *p)
 Return transport of dialog. More...
 
static int get_transport_str2enum (const char *transport)
 Return int representing a bit field of transport types found in const char *transport. More...
 
static const char * gettag (const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize)
 Get tag from packet. More...
 
static int handle_cc_notify (struct sip_pvt *pvt, struct sip_request *req)
 
static int handle_cc_subscribe (struct sip_pvt *p, struct sip_request *req)
 
static int handle_common_options (struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v)
 Handle flag-type options common to configuration of devices - peers. More...
 
static int handle_incoming (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int *recount, int *nounlock)
 Handle incoming SIP requests (methods) More...
 
static int handle_invite_replaces (struct sip_pvt *p, struct sip_request *req, int *nounlock, struct sip_pvt *replaces_pvt, struct ast_channel *replaces_chan)
 Handle the transfer part of INVITE with a replaces: header,. More...
 
static int handle_request_bye (struct sip_pvt *p, struct sip_request *req)
 Handle incoming BYE request. More...
 
static int handle_request_cancel (struct sip_pvt *p, struct sip_request *req)
 Handle incoming CANCEL request. More...
 
static int handle_request_do (struct sip_request *req, struct ast_sockaddr *addr)
 Handle incoming SIP message - request or response. More...
 
static void handle_request_info (struct sip_pvt *p, struct sip_request *req)
 Receive SIP INFO Message. More...
 
static int handle_request_invite (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, uint32_t seqno, int *recount, const char *e, int *nounlock)
 Handle incoming INVITE request. More...
 
static int handle_request_invite_st (struct sip_pvt *p, struct sip_request *req, int reinvite)
 
static int handle_request_message (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 Handle incoming MESSAGE request. More...
 
static int handle_request_notify (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, uint32_t seqno, const char *e)
 Handle incoming notifications. More...
 
static int handle_request_options (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 Handle incoming OPTIONS request An OPTIONS request should be answered like an INVITE from the same UA, including SDP. More...
 
static int handle_request_publish (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const uint32_t seqno, const char *uri)
 
static int handle_request_refer (struct sip_pvt *p, struct sip_request *req, uint32_t seqno, int *nounlock)
 
static int handle_request_register (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 Handle incoming REGISTER request. More...
 
static int handle_request_subscribe (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, uint32_t seqno, const char *e)
 Handle incoming SUBSCRIBE request. More...
 
static int handle_request_update (struct sip_pvt *p, struct sip_request *req)
 bare-bones support for SIP UPDATE More...
 
static void handle_response (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle SIP response in dialogue. More...
 
static void handle_response_info (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void handle_response_invite (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle SIP response to INVITE dialogue. More...
 
static void handle_response_message (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void handle_response_notify (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle SIP response in NOTIFY transaction We've sent a NOTIFY, now handle responses to it. More...
 
static void handle_response_peerpoke (struct sip_pvt *p, int resp, struct sip_request *req)
 Handle qualification responses (OPTIONS) More...
 
static void handle_response_publish (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void handle_response_refer (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle SIP response in REFER transaction We've sent a REFER, now handle responses to it. More...
 
static int handle_response_register (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle responses on REGISTER to services. More...
 
static void handle_response_subscribe (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle SIP response in SUBSCRIBE transaction. More...
 
static void handle_response_update (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle authentication challenge for SIP UPDATE. More...
 
static int handle_sip_publish_initial (struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const int expires)
 
static int handle_sip_publish_modify (struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char *const etag, const int expires)
 
static int handle_sip_publish_refresh (struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char *const etag, const int expires)
 
static int handle_sip_publish_remove (struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char *const etag)
 
static int handle_t38_options (struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v, unsigned int *maxdatagram)
 Handle T.38 configuration options common to users and peers. More...
 
const char * hangup_cause2sip (int cause)
 Convert Asterisk hangup causes to SIP codes. More...
 
int hangup_sip2cause (int cause)
 Convert SIP hangup causes to Asterisk hangup causes. More...
 
static int has_media_level_attribute (int start, struct sip_request *req, const char *attr)
 
static int has_media_stream (struct sip_pvt *p, enum media_type m)
 Check the media stream list to see if the given type already exists. More...
 
static int init_req (struct sip_request *req, int sipmethod, const char *recip)
 Initialize SIP request. More...
 
static int init_resp (struct sip_request *resp, const char *msg)
 Initialize SIP response, based on SIP request. More...
 
static int initialize_escs (void)
 
static void initialize_initreq (struct sip_pvt *p, struct sip_request *req)
 Initialize the initital request packet in the pvt structure. This packet is used for creating replies and future requests in a dialog. More...
 
static int initialize_udptl (struct sip_pvt *p)
 
static void initreqprep (struct sip_request *req, struct sip_pvt *p, int sipmethod, const char *const explicit_uri)
 Initiate new SIP request to peer/user. More...
 
static const char * insecure2str (int mode)
 Convert Insecure setting to printable string. More...
 
static int interpret_t38_parameters (struct sip_pvt *p, const struct ast_control_t38_parameters *parameters)
 Helper function which updates T.38 capability information and triggers a reinvite. More...
 
static int is_method_allowed (unsigned int *allowed_methods, enum sipmethod method)
 Check if method is allowed for a device or a dialog. More...
 
static int load_module (void)
 Load the module. More...
 
static int local_attended_transfer (struct sip_pvt *transferer, struct ast_channel *transferer_chan, uint32_t seqno, int *nounlock)
 Find all call legs and bridge transferee with target called from handle_request_refer. More...
 
static void lws2sws (struct ast_str *data)
 Parse multiline SIP headers into one header This is enabled if pedanticsipchecking is enabled. More...
 
static void make_our_tag (struct sip_pvt *pvt)
 Make our SIP dialog tag. More...
 
static int manager_show_registry (struct mansession *s, const struct message *m)
 Show SIP registrations in the manager API. More...
 
static int manager_sip_peer_status (struct mansession *s, const struct message *m)
 Show SIP peers in the manager API
More...
 
static int manager_sip_qualify_peer (struct mansession *s, const struct message *m)
 Qualify SIP peers in the manager API
More...
 
static int manager_sip_show_peer (struct mansession *s, const struct message *m)
 Show SIP peers in the manager API
More...
 
static int manager_sip_show_peers (struct mansession *s, const struct message *m)
 Show SIP peers in the manager API. More...
 
static int manager_sipnotify (struct mansession *s, const struct message *m)
 
static int map_s_x (const struct _map_x_s *table, const char *s, int errorvalue)
 map from a string to an integer value, case insensitive. If no match is found, return errorvalue. More...
 
static const char * map_x_s (const struct _map_x_s *table, int x, const char *errorstring)
 map from an integer value to a string. If no match is found, return errorstring More...
 
static void mark_method_allowed (unsigned int *allowed_methods, enum sipmethod method)
 
static void mark_method_unallowed (unsigned int *allowed_methods, enum sipmethod method)
 
static void mark_parsed_methods (unsigned int *methods, char *methods_str)
 
static int match_and_cleanup_peer_sched (void *peerobj, void *arg, int flags)
 
static enum match_req_res match_req_to_dialog (struct sip_pvt *sip_pvt_ptr, struct match_req_args *arg)
 Match a incoming Request/Response to a dialog. More...
 
static int method_match (enum sipmethod id, const char *name)
 returns true if 'name' (with optional trailing whitespace) matches the sip method 'id'. Strictly speaking, SIP methods are case SENSITIVE, but we do a case-insensitive comparison to be more tolerant. following Jon Postel's rule: Be gentle in what you accept, strict with what you send More...
 
static void mwi_event_cb (void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
 Receive MWI events that we have subscribed to. More...
 
static int network_change_sched_cb (const void *data)
 
static void network_change_stasis_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void network_change_stasis_subscribe (void)
 
static void network_change_stasis_unsubscribe (void)
 
static struct sip_proxyobproxy_get (struct sip_pvt *dialog, struct sip_peer *peer)
 Get default outbound proxy or global proxy. More...
 
static void offered_media_list_destroy (struct sip_pvt *p)
 Destroy SDP media offer list. More...
 
static void on_dns_update_mwi (struct ast_sockaddr *old, struct ast_sockaddr *new, void *data)
 
static void on_dns_update_peer (struct ast_sockaddr *old, struct ast_sockaddr *new, void *data)
 
static void on_dns_update_registry (struct ast_sockaddr *old, struct ast_sockaddr *new, void *data)
 
static unsigned int parse_allowed_methods (struct sip_request *req)
 parse the Allow header to see what methods the endpoint we are communicating with allows. More...
 
static void parse_copy (struct sip_request *dst, const struct sip_request *src)
 Copy SIP request, parse it. More...
 
static int parse_minse (const char *p_hdrval, int *const p_interval)
 Session-Timers: Function for parsing Min-SE header. More...
 
static void parse_moved_contact (struct sip_pvt *p, struct sip_request *req, char **name, char **number, int set_call_forward)
 Parse 302 Moved temporalily response. More...
 
static int parse_ok_contact (struct sip_pvt *pvt, struct sip_request *req)
 Save contact header for 200 OK on INVITE. More...
 
static void parse_oli (struct sip_request *req, struct ast_channel *chan)
 Check for the presence of OLI tag(s) in the From header and set on the channel. More...
 
static enum parse_register_result parse_register_contact (struct sip_pvt *pvt, struct sip_peer *peer, struct sip_request *req)
 Parse contact header and save registration (peer registration) More...
 
static int parse_request (struct sip_request *req)
 Parse a SIP message. More...
 
static int parse_session_expires (const char *p_hdrval, int *const p_interval, enum st_refresher_param *const p_ref)
 Session-Timers: Function for parsing Session-Expires header. More...
 
static int parse_uri_legacy_check (char *uri, const char *scheme, char **user, char **pass, char **hostport, char **transport)
 parse uri in a way that allows semicolon stripping if legacy mode is enabled More...
 
static int peer_cmp_cb (void *obj, void *arg, int flags)
 
static int peer_dump_func (void *userobj, void *arg, int flags)
 
static int peer_hash_cb (const void *obj, const int flags)
 
static int peer_ipcmp_cb_full (void *obj, void *arg, void *data, int flags)
 
static int peer_iphash_cb (const void *obj, const int flags)
 
static void peer_mailboxes_to_str (struct ast_str **mailbox_str, struct sip_peer *peer)
 list peer mailboxes to CLI More...
 
static int peer_markall_autopeers_func (void *device, void *arg, int flags)
 
static int peer_markall_func (void *device, void *arg, int flags)
 
static void peer_sched_cleanup (struct sip_peer *peer)
 
static int peer_status (struct sip_peer *peer, char *status, int statuslen)
 
int peercomparefunc (const void *a, const void *b)
 
static int pidf_validate_presence (struct ast_xml_doc *doc)
 
static int pidf_validate_tuple (struct ast_xml_node *tuple_node)
 
unsigned int port_str2int (const char *pt, unsigned int standard)
 converts ascii port to int representation. If no pt buffer is provided or the pt has errors when being converted to an int value, the port provided as the standard is used. More...
 
static void print_group (int fd, ast_group_t group, int crlf)
 Print call group and pickup group. More...
 
static void print_named_groups (int fd, struct ast_namedgroups *group, int crlf)
 Print named call groups and pickup groups. More...
 
static void proc_422_rsp (struct sip_pvt *p, struct sip_request *rsp)
 Handle 422 response to INVITE with session-timer requested. More...
 
static int proc_session_timer (const void *vp)
 Session-Timers: Process session refresh timeout event. More...
 
static int process_crypto (struct sip_pvt *p, struct ast_rtp_instance *rtp, struct ast_sdp_srtp **srtp, const char *a)
 
static int process_sdp (struct sip_pvt *p, struct sip_request *req, int t38action, int is_offer)
 Process SIP SDP offer, select formats and activate media channels If offer is rejected, we will not change any properties of the call Return 0 on success, a negative value on errors. Must be called after find_sdp(). More...
 
static int process_sdp_a_audio (const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newaudiortp, int *last_rtpmap_codec)
 
static int process_sdp_a_dtls (const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance)
 
static int process_sdp_a_ice (const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance, int rtcp_mux)
 
static int process_sdp_a_image (const char *a, struct sip_pvt *p)
 
static int process_sdp_a_rtcp_mux (const char *a, struct sip_pvt *p, int *requested)
 
static int process_sdp_a_sendonly (const char *a, int *sendonly)
 
static int process_sdp_a_text (const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newtextrtp, char *red_fmtp, int *red_num_gen, int *red_data_pt, int *last_rtpmap_codec)
 
static int process_sdp_a_video (const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newvideortp, int *last_rtpmap_codec)
 
static int process_sdp_c (const char *c, struct ast_sockaddr *addr)
 
static int process_sdp_o (const char *o, struct sip_pvt *p)
 
static int process_via (struct sip_pvt *p, const struct sip_request *req)
 Process the Via header according to RFC 3261 section 18.2.2. More...
 
static struct sip_proxyproxy_from_config (const char *proxy, int sipconf_lineno, struct sip_proxy *dest)
 Parse proxy string and return an ao2_alloc'd proxy. If dest is non-NULL, no allocation is performed and dest is used instead. On error NULL is returned. More...
 
static int proxy_update (struct sip_proxy *proxy)
 
static int publish_expire (const void *data)
 
static void publish_qualify_peer_done (const char *id, const char *peer)
 
static void pvt_set_needdestroy (struct sip_pvt *pvt, const char *reason)
 
static int read_raw_content_length (const char *message)
 Get the content length from an unparsed SIP message. More...
 
static struct sip_peerrealtime_peer (const char *newpeername, struct ast_sockaddr *addr, char *callbackexten, int devstate_only, int which_objects)
 realtime_peer: Get peer from realtime storage Checks the "sippeers" realtime family from extconfig.conf Checks the "sipregs" realtime family from extconfig.conf if it's configured. This returns a pointer to a peer and because we use build_peer, we can rest assured that the refcount is bumped. More...
 
static int realtime_peer_by_addr (const char **name, struct ast_sockaddr *addr, const char *ipaddr, const char *callbackexten, struct ast_variable **var, struct ast_variable **varregs)
 
static int realtime_peer_by_name (const char *const *name, struct ast_sockaddr *addr, const char *ipaddr, struct ast_variable **var, struct ast_variable **varregs)
 
static struct ast_variablerealtime_peer_get_sippeer_helper (const char **name, struct ast_variable **varregs)
 
static void realtime_update_peer (const char *peername, struct ast_sockaddr *addr, const char *defaultuser, const char *fullcontact, const char *useragent, int expirey, unsigned short deprecated_username, int lastms, const char *path)
 Update peer object in realtime storage If the Asterisk system name is set in asterisk.conf, we will use that name and store that in the "regserver" field in the sippeers table to facilitate multi-server setups. More...
 
static void receive_message (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 Receive SIP MESSAGE method messages. More...
 
static void ref_proxy (struct sip_pvt *pvt, struct sip_proxy *proxy)
 
static const char * referstatus2str (enum referstatus rstatus)
 Convert transfer status to string. More...
 
static void reg_source_db (struct sip_peer *peer)
 Get registration details from Asterisk DB. More...
 
static void register_peer_exten (struct sip_peer *peer, int onoff)
 Automatically add peer extension to dial plan. More...
 
static int register_realtime_peers_with_callbackextens (void)
 
static enum check_auth_result register_verify (struct sip_pvt *p, struct ast_sockaddr *addr, struct sip_request *req, const char *uri)
 Verify registration of user. More...
 
static int registry_cmp_cb (void *obj, void *arg, int flags)
 
static int registry_hash_cb (const void *obj, const int flags)
 
static const char * regstate2str (enum sipregistrystate regstate)
 Convert registration state status to string. More...
 
static int reinvite_timeout (const void *data)
 
static int reload (void)
 Part of Asterisk module interface. More...
 
static int reload_config (enum channelreloadreason reason)
 Re-read SIP.conf config file. More...
 
static char * remove_uri_parameters (char *uri)
 Remove URI parameters at end of URI, not in username part though. More...
 
static int reply_digest (struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len)
 reply to authentication for outbound registrations More...
 
static int reqprep (struct sip_request *req, struct sip_pvt *p, int sipmethod, uint32_t seqno, int newbranch)
 Initialize a SIP request message (not the initial one in a dialog) More...
 
static int resp_needs_contact (const char *msg, enum sipmethod method)
 Test if this response needs a contact header. More...
 
static int respprep (struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req)
 Prepare SIP response packet. More...
 
static int restart_monitor (void)
 Start the channel monitor thread. More...
 
static void restart_session_timer (struct sip_pvt *p)
 Session-Timers: Restart session timer. More...
 
static int retrans_pkt (const void *data)
 Retransmit SIP message if no answer. More...
 
static void sched_check_pendings (struct sip_pvt *pvt)
 
static void send_check_user_failure_response (struct sip_pvt *p, struct sip_request *req, int res, enum xmittype reliable)
 
static void send_manager_peer_status (struct mansession *s, struct sip_peer *peer, const char *idText)
 
static int send_provisional_keepalive (const void *data)
 
static int send_provisional_keepalive_full (struct sip_pvt *pvt, int with_sdp)
 
static int send_provisional_keepalive_with_sdp (const void *data)
 
static int send_request (struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, uint32_t seqno)
 
static int send_response (struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, uint32_t seqno)
 Transmit response on SIP request. More...
 
static void send_session_timeout (struct ast_channel *chan, const char *source)
 Sends a session timeout channel blob used to produce SessionTimeout AMI messages. More...
 
static enum ast_cc_service_type service_string_to_service_type (const char *const service_string)
 
static struct ast_manager_event_blobsession_timeout_to_ami (struct stasis_message *msg)
 
static int set_address_from_contact (struct sip_pvt *pvt)
 Change the other partys IP address based on given contact. More...
 
static void set_destination (struct sip_pvt *p, const char *uri)
 Set destination from SIP URI. More...
 
static void set_ice_components (struct sip_pvt *p, struct ast_rtp_instance *instance, int remote_rtcp_mux)
 
static void set_insecure_flags (struct ast_flags *flags, const char *value, int lineno)
 Parse insecure= setting in sip.conf and set flags according to setting. More...
 
static int set_message_vars_from_req (struct ast_msg *msg, struct sip_request *req)
 
static void set_peer_defaults (struct sip_peer *peer)
 Set peer defaults before configuring specific configurations. More...
 
static void set_peer_nat (const struct sip_pvt *p, struct sip_peer *peer)
 Set the peers nat flags if they are using auto_* settings. More...
 
static unsigned int set_pvt_allowed_methods (struct sip_pvt *pvt, struct sip_request *req)
 
static void set_socket_transport (struct sip_socket *socket, int transport)
 
static void set_t38_capabilities (struct sip_pvt *p)
 Set the global T38 capabilities on a SIP dialog structure. More...
 
static int show_channels_cb (struct sip_pvt *cur, struct __show_chan_arg *arg)
 callback for show channel|subscription More...
 
static int show_chanstats_cb (struct sip_pvt *cur, struct __show_chan_arg *arg)
 Callback for show_chanstats. More...
 
static void shutdown_mwi_subscription (struct sip_subscription_mwi *mwi)
 
static int sip_addheader (struct ast_channel *chan, const char *data)
 Add a SIP header to an outbound INVITE. More...
 
static int sip_allow_anyrtp_remote (struct ast_channel *chan1, struct ast_rtp_instance *instance, const char *rtptype)
 
static int sip_allow_rtp_remote (struct ast_channel *chan1, struct ast_rtp_instance *instance)
 
static int sip_allow_vrtp_remote (struct ast_channel *chan1, struct ast_rtp_instance *instance)
 
static void sip_alreadygone (struct sip_pvt *dialog)
 Encapsulate setting of SIP_ALREADYGONE to be able to trace it with debugging. More...
 
static int sip_answer (struct ast_channel *ast)
 sip_answer: Answer SIP call , send 200 OK on Invite Part of PBX interface More...
 
void sip_auth_headers (enum sip_auth_type code, char **header, char **respheader)
 return the request and response header for a 401 or 407 code More...
 
static int sip_call (struct ast_channel *ast, const char *dest, int timeout)
 Initiate SIP call from PBX used from the dial() application
More...
 
void sip_cancel_destroy (struct sip_pvt *pvt)
 Cancel destruction of SIP dialog. More...
 
static void sip_cc_agent_destructor (struct ast_cc_agent *agent)
 
static int sip_cc_agent_init (struct ast_cc_agent *agent, struct ast_channel *chan)
 
static int sip_cc_agent_recall (struct ast_cc_agent *agent)
 
static void sip_cc_agent_respond (struct ast_cc_agent *agent, enum ast_cc_agent_response_reason reason)
 
static int sip_cc_agent_start_monitoring (struct ast_cc_agent *agent)
 
static int sip_cc_agent_start_offer_timer (struct ast_cc_agent *agent)
 
static int sip_cc_agent_status_request (struct ast_cc_agent *agent)
 
static int sip_cc_agent_stop_offer_timer (struct ast_cc_agent *agent)
 
static int sip_cc_monitor_cancel_available_timer (struct ast_cc_monitor *monitor, int *sched_id)
 
static void sip_cc_monitor_destructor (void *private_data)
 
static int sip_cc_monitor_request_cc (struct ast_cc_monitor *monitor, int *available_timer_id)
 
static int sip_cc_monitor_suspend (struct ast_cc_monitor *monitor)
 
static int sip_cc_monitor_unsuspend (struct ast_cc_monitor *monitor)
 
static int sip_check_authtimeout (time_t start)
 Check if the authtimeout has expired. More...
 
static char * sip_cli_notify (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Cli command to send SIP notify to peer. More...
 
static int sip_debug_test_addr (const struct ast_sockaddr *addr)
 See if we pass debug IP filter. More...
 
static int sip_debug_test_pvt (struct sip_pvt *p)
 Test PVT for debugging output. More...
 
static void sip_destroy_peer (struct sip_peer *peer)
 Destroy peer object from memory. More...
 
static void sip_destroy_peer_fn (void *peer)
 
static int sip_devicestate (const char *data)
 Part of PBX channel interface. More...
 
void sip_digest_parser (char *c, struct digestkeys *keys)
 Takes the digest response and parses it. More...
 
static char * sip_do_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Turn on SIP debugging (CLI command) More...
 
static char * sip_do_debug_ip (int fd, const char *arg)
 Enable SIP Debugging for a single IP. More...
 
static char * sip_do_debug_peer (int fd, const char *arg)
 Turn on SIP debugging for a given peer. More...
 
static int sip_do_reload (enum channelreloadreason reason)
 Reload module. More...
 
static int sip_dtmfmode (struct ast_channel *chan, const char *data)
 Set the DTMFmode for an outbound SIP call (application) More...
 
static void sip_dump_history (struct sip_pvt *dialog)
 Dump SIP history to debug log file at end of lifespan for SIP dialog. More...
 
static int sip_epa_register (const struct epa_static_data *static_data)
 
static void sip_epa_unregister_all (void)
 
struct sip_peersip_find_peer (const char *peer, struct ast_sockaddr *addr, int realtime, int which_objects, int devstate_only, int transport)
 Locate device by name or ip address. More...
 
static struct sip_peersip_find_peer_by_ip_and_exten (struct ast_sockaddr *addr, char *callbackexten, int transport)
 
static struct sip_peersip_find_peer_full (const char *peer, struct ast_sockaddr *addr, char *callbackexten, int realtime, int which_objects, int devstate_only, int transport)
 
static int sip_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
 sip_fixup: Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links More...
 
static const char * sip_get_callid (struct ast_channel *chan)
 Deliver SIP call ID for the call. More...
 
static int sip_get_cc_information (struct sip_request *req, char *subscribe_uri, size_t size, enum ast_cc_service_type *service)
 
static void sip_get_codec (struct ast_channel *chan, struct ast_format_cap *result)
 
const char * sip_get_header (const struct sip_request *req, const char *name)
 Get header from SIP request. More...
 
static enum ast_rtp_glue_result sip_get_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance)
 
const char * sip_get_transport (enum ast_transport t)
 Return transport as string. More...
 
static enum ast_rtp_glue_result sip_get_trtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance)
 
static enum ast_rtp_glue_result sip_get_vrtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance)
 
static void sip_handle_cc (struct sip_pvt *pvt, struct sip_request *req, enum ast_cc_service_type service)
 Determine what, if any, CC has been offered and queue a CC frame if possible. More...
 
static int sip_hangup (struct ast_channel *ast)
 sip_hangup: Hangup SIP call Part of PBX interface, called from ast_hangup More...
 
static int sip_indicate (struct ast_channel *ast, int condition, const void *data, size_t datalen)
 Play indication to user With SIP a lot of indications is sent as messages, letting the device play the indication - busy signal, congestion etc. More...
 
static int sip_is_token (const char *str)
 
static int sip_is_xml_parsable (void)
 
static void sip_keepalive_all_peers (void)
 Send a keepalive to all known peers. More...
 
static int sip_monitor_instance_cmp_fn (void *obj, void *arg, int flags)
 
static void sip_monitor_instance_destructor (void *data)
 
static int sip_monitor_instance_hash_fn (const void *obj, const int flags)
 
static struct sip_monitor_instancesip_monitor_instance_init (int core_id, const char *const subscribe_uri, const char *const peername, const char *const device_name)
 
static int sip_msg_send (const struct ast_msg *msg, const char *to, const char *from)
 
static const char * sip_nat_mode (const struct sip_pvt *p)
 Display SIP nat mode. More...
 
static struct ast_channelsip_new (struct sip_pvt *i, int state, const char *title, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, ast_callid callid)
 Initiate a call in the SIP channel. More...
 
static int sip_notify_alloc (struct sip_pvt *p)
 Allocate SIP refer structure. More...
 
static int sip_offer_timer_expire (const void *data)
 
static void sip_peer_hold (struct sip_pvt *p, int hold)
 Change onhold state of a peer using a pvt structure. More...
 
static int sip_pickup (struct ast_channel *chan)
 Pickup a call using the subsystem in features.c This is executed in a separate thread. More...
 
static void * sip_pickup_thread (void *stuff)
 SIP pickup support function Starts in a new thread, then pickup the call. More...
 
static int sip_pidf_validate (struct sip_request *req, struct ast_xml_doc **pidf_doc)
 Makes sure that body is properly formatted PIDF. More...
 
static void sip_pkt_dtor (void *vdoomed)
 
static void sip_poke_all_peers (void)
 Send a poke to all known peers. More...
 
static int sip_poke_noanswer (const void *data)
 React to lack of answer to Qualify poke. More...
 
static int sip_poke_peer (struct sip_peer *peer, int force)
 Check availability of peer, also keep NAT open. More...
 
static int sip_poke_peer_now (const void *data)
 
static int sip_poke_peer_s (const void *data)
 Poke peer (send qualify to check if peer is alive and well) More...
 
static int sip_prepare_socket (struct sip_pvt *p)
 
static char * sip_prune_realtime (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Remove temporary realtime objects from memory (CLI) More...
 
static void sip_publish_registry (const char *username, const char *domain, const char *status)
 
static void sip_pvt_callid_set (struct sip_pvt *pvt, ast_callid callid)
 
static void sip_pvt_dtor (void *vdoomed)
 ao2 destructor for SIP dialog structure More...
 
static struct ast_channelsip_pvt_lock_full (struct sip_pvt *pvt)
 
static char * sip_qualify_peer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Send an OPTIONS packet to a SIP peer. More...
 
static int sip_queryoption (struct ast_channel *chan, int option, void *data, int *datalen)
 Query an option on a SIP dialog. More...
 
static void sip_queue_hangup_cause (struct sip_pvt *p, int cause)
 
static struct ast_framesip_read (struct ast_channel *ast)
 Read SIP RTP from channel. More...
 
static const struct ast_sockaddrsip_real_dst (const struct sip_pvt *p)
 The real destination address for a write. More...
 
static const char * sip_reason_code_to_str (struct ast_party_redirecting_reason *reason)
 
static int sip_refer_alloc (struct sip_pvt *p)
 Allocate SIP refer structure. More...
 
static void sip_refer_destroy (struct sip_pvt *p)
 Destroy SIP refer structure. More...
 
static int sip_reg_timeout (const void *data)
 Registration request timeout, register again. More...
 
static int sip_register (const char *value, int lineno)
 create sip_registry object from register=> line in sip.conf and link into reg container More...
 
static void sip_register_tests (void)
 SIP test registration. More...
 
static void sip_registry_destroy (void *obj)
 Destroy registry object Objects created with the register= statement in static configuration. More...
 
static int sip_reinvite_retry (const void *data)
 Reset the NEEDREINVITE flag after waiting when we get 491 on a Re-invite to avoid race conditions between asterisk servers. More...
 
static char * sip_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Force reload of module from cli. More...
 
static int sip_removeheader (struct ast_channel *chan, const char *data)
 Remove SIP headers added previously with SipAddHeader application. More...
 
static struct ast_channelsip_request_call (const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *dest, int *cause)
 PBX interface function -build SIP pvt structure SIP calls initiated by the PBX arrive here. More...
 
static int sip_reregister (const void *data)
 Update registration with SIP Proxy. More...
 
static struct ast_framesip_rtp_read (struct ast_channel *ast, struct sip_pvt *p, int *faxdetect)
 Read RTP from network. More...
 
static const char * sip_sanitized_host (const char *host)
 
void sip_scheddestroy (struct sip_pvt *p, int ms)
 Schedule destruction of SIP dialog. More...
 
void sip_scheddestroy_final (struct sip_pvt *p, int ms)
 Schedule final destruction of SIP dialog. More...
 
static int sip_scheddestroy_full (struct sip_pvt *p, int ms)
 
static void sip_send_all_mwi_subscriptions (void)
 Send all MWI subscriptions. More...
 
static void sip_send_all_registers (void)
 Send all known registrations. More...
 
static int sip_send_keepalive (const void *data)
 Send keep alive packet to peer. More...
 
static int sip_send_mwi_to_peer (struct sip_peer *peer, int cache_only)
 Send message waiting indication to alert peer that they've got voicemail. More...
 
static int sip_senddigit_begin (struct ast_channel *ast, char digit)
 
static int sip_senddigit_end (struct ast_channel *ast, char digit, unsigned int duration)
 Send DTMF character on SIP channel within one call, we're able to transmit in many methods simultaneously. More...
 
static int sip_sendhtml (struct ast_channel *chan, int subclass, const char *data, int datalen)
 Send message with Access-URL header, if this is an HTML URL only! More...
 
static int sip_sendtext (struct ast_channel *ast, const char *text)
 
static void sip_set_default_format_capabilities (struct ast_format_cap *cap)
 
static char * sip_set_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Enable/Disable SIP History logging (CLI) More...
 
static void sip_set_owner (struct sip_pvt *p, struct ast_channel *chan)
 Set the owning channel on the sip_pvt object. More...
 
static void sip_set_redirstr (struct sip_pvt *p, char *reason)
 Translate referring cause. More...
 
static int sip_set_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, const struct ast_format_cap *cap, int nat_active)
 
static int sip_setoption (struct ast_channel *chan, int option, void *data, int datalen)
 Set an option on a SIP dialog. More...
 
static char * sip_show_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show details of one active dialog. More...
 
static char * sip_show_channels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI for show channels or subscriptions. This is a new-style CLI handler so a single function contains the prototype for the function, the 'generator' to produce multiple entries in case it is required, and the actual handler for the command. More...
 
static char * sip_show_channelstats (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 SIP show channelstats CLI (main function) More...
 
static char * sip_show_domains (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to list local domains. More...
 
static char * sip_show_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show history details of one dialog. More...
 
static char * sip_show_inuse (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI Command to show calls within limits set by call_limit. More...
 
static char * sip_show_mwi (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * sip_show_objects (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 List all allocated SIP Objects (realtime or static) More...
 
static char * sip_show_peer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show one peer in detail. More...
 
static char * sip_show_peers (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI Show Peers command. More...
 
static char * sip_show_registry (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show SIP Registry (registrations with other SIP proxies. More...
 
static char * sip_show_sched (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * sip_show_settings (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 List global settings for the SIP channel. More...
 
static char * sip_show_tcp (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show active TCP connections. More...
 
static char * sip_show_user (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show one user in detail. More...
 
static char * sip_show_users (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI Command 'SIP Show Users'. More...
 
static int sip_sipredirect (struct sip_pvt *p, const char *dest)
 Transfer call before connect with a 302 redirect. More...
 
static struct sip_st_dlgsip_st_alloc (struct sip_pvt *const p)
 Allocate Session-Timers struct w/in dialog. More...
 
static int sip_standard_port (enum ast_transport type, int port)
 Returns the port to use for this socket. More...
 
static int sip_subscribe_mwi (const char *value, int lineno)
 Parse mwi=> line in sip.conf and add to list. More...
 
static void sip_subscribe_mwi_destroy (void *data)
 Destroy MWI subscription object. More...
 
static int sip_subscribe_mwi_do (const void *data)
 Send a subscription or resubscription for MWI. More...
 
static int sip_t38_abort (const void *data)
 Called to deny a T38 reinvite if the core does not respond to our request. More...
 
static struct ast_tcptls_session_instancesip_tcp_locate (struct ast_sockaddr *s)
 Find thread for TCP/TLS session (based on IP/Port. More...
 
static void * sip_tcp_worker_fn (void *data)
 SIP TCP connection handler. More...
 
static void sip_tcptls_client_args_destructor (void *obj)
 
static int sip_tcptls_read (struct sip_request *req, struct ast_tcptls_session_instance *tcptls_session, int authenticated, time_t start)
 
static int sip_tcptls_write (struct ast_tcptls_session_instance *tcptls_session, const void *buf, size_t len)
 used to indicate to a tcptls thread that data is ready to be written More...
 
static struct sip_threadinfosip_threadinfo_create (struct ast_tcptls_session_instance *tcptls_session, int transport)
 creates a sip_threadinfo object and links it into the threadt table. More...
 
static void sip_threadinfo_destructor (void *obj)
 
static int sip_transfer (struct ast_channel *ast, const char *dest)
 Transfer SIP call. More...
 
static char * sip_unregister (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Unregister (force expiration) a SIP peer in the registry via CLI. More...
 
static void sip_unregister_tests (void)
 SIP test registration. More...
 
static void sip_websocket_callback (struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers)
 SIP WebSocket connection handler. More...
 
static int sip_write (struct ast_channel *ast, struct ast_frame *frame)
 Send frame to media channel (rtp) More...
 
static int sipinfo_send (struct ast_channel *chan, struct ast_variable *headers, const char *content_type, const char *content, const char *useragent_filter)
 
static int sipsock_read (int *id, int fd, short events, void *ignore)
 Read data from SIP UDP socket. More...
 
static int sockaddr_is_null_or_any (const struct ast_sockaddr *addr)
 
static enum st_mode st_get_mode (struct sip_pvt *p, int no_cached)
 Get the session-timer mode. More...
 
static enum st_refresher st_get_refresher (struct sip_pvt *p)
 Get the entity (UAC or UAS) that's acting as the session-timer refresher. More...
 
static int st_get_se (struct sip_pvt *p, int max)
 Get Max or Min SE (session timer expiry) More...
 
static void start_ice (struct ast_rtp_instance *instance, int offer)
 Start ICE negotiation on an RTP instance. More...
 
static void start_mwi_subscription (struct sip_subscription_mwi *mwi, int ms)
 
static void start_register_timeout (struct sip_registry *reg)
 
static void start_reregister_timeout (struct sip_registry *reg, int ms)
 
static void start_session_timer (struct sip_pvt *pvt)
 Session-Timers: Start session timer. More...
 
static void start_t38_abort_timer (struct sip_pvt *pvt)
 
static void startup_event_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 Event callback which indicates we're fully booted. More...
 
 STASIS_MESSAGE_TYPE_DEFN_LOCAL (session_timeout_type,.to_ami=session_timeout_to_ami,)
 
static void state_notify_build_xml (struct state_notify_data *data, int full, const char *exten, const char *context, struct ast_str **tmp, struct sip_pvt *p, int subscribed, const char *mfrom, const char *mto)
 Builds XML portion of NOTIFY messages for presence or dialog updates. More...
 
static const char * stmode2str (enum st_mode m)
 
static void stop_media_flows (struct sip_pvt *p)
 Immediately stop RTP, VRTP and UDPTL as applicable. More...
 
static void stop_provisional_keepalive (struct sip_pvt *pvt)
 
static void stop_register_timeout (struct sip_registry *reg)
 
static void stop_reinvite_retry (struct sip_pvt *pvt)
 
static void stop_reinviteid (struct sip_pvt *pvt)
 
static void stop_retrans_pkt (struct sip_pkt *pkt)
 
static void stop_session_timer (struct sip_pvt *pvt)
 Session-Timers: Stop session timer. More...
 
static void stop_t38_abort_timer (struct sip_pvt *pvt)
 
static int str2dtmfmode (const char *str)
 maps a string to dtmfmode, returns -1 on error More...
 
static enum st_mode str2stmode (const char *s)
 
static enum st_refresher_param str2strefresherparam (const char *s)
 
static const char * strefresher2str (enum st_refresher r)
 
static const char * strefresherparam2str (enum st_refresher_param r)
 
static const char * subscription_type2str (enum subscriptiontype subtype)
 Show subscription type in string format. More...
 
static unsigned int t38_get_rate (enum ast_control_t38_rate rate)
 Get Max T.38 Transmission rate from T38 capabilities. More...
 
static void tcptls_packet_destructor (void *obj)
 
static struct sip_peertemp_peer (const char *name)
 Create temporary peer (used in autocreatepeer mode) More...
 
static void temp_pvt_cleanup (void *)
 
static int temp_pvt_init (void *)
 
static char * terminate_uri (char *uri)
 
static int threadinfo_locate_cb (void *obj, void *arg, int flags)
 
static int threadt_cmp_cb (void *obj, void *arg, int flags)
 
static int threadt_hash_cb (const void *obj, const int flags)
 
static char * transfermode2str (enum transfermodes mode)
 Convert transfer mode to text string. More...
 
static int transmit_cc_notify (struct ast_cc_agent *agent, struct sip_pvt *subscription, enum sip_cc_notify_state state)
 
static void transmit_fake_auth_response (struct sip_pvt *p, struct sip_request *req, enum xmittype reliable)
 Send a fake 401 Unauthorized response when the administrator wants to hide the names of local devices from fishers. More...
 
static int transmit_info_with_aoc (struct sip_pvt *p, struct ast_aoc_decoded *decoded)
 Send SIP INFO advice of charge message. More...
 
static int transmit_info_with_digit (struct sip_pvt *p, const char digit, unsigned int duration)
 Send SIP INFO dtmf message, see Cisco documentation on cisco.com. More...
 
static int transmit_info_with_vidupdate (struct sip_pvt *p)
 Send SIP INFO with video update request. More...
 
static int transmit_invite (struct sip_pvt *p, int sipmethod, int sdp, int init, const char *const explicit_uri)
 Build REFER/INVITE/OPTIONS/SUBSCRIBE message and transmit it. More...
 
static int transmit_message (struct sip_pvt *p, int init, int auth)
 Transmit with SIP MESSAGE method. More...
 
static int transmit_notify_with_mwi (struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten)
 Notify user of messages waiting in voicemail (RFC3842) More...
 
static int transmit_notify_with_sipfrag (struct sip_pvt *p, int cseq, char *message, int terminate)
 Notify a transferring party of the status of transfer (RFC3515) More...
 
static int transmit_provisional_response (struct sip_pvt *p, const char *msg, const struct sip_request *req, int with_sdp)
 
static int transmit_publish (struct sip_epa_entry *epa_entry, enum sip_publish_type publish_type, const char *const explicit_uri)
 
static int transmit_refer (struct sip_pvt *p, const char *dest)
 Transmit SIP REFER message (initiated by the transfer() dialplan application. More...
 
static int transmit_register (struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
 Transmit register to SIP proxy or UA auth = NULL on the initial registration (from sip_reregister()) More...
 
static int transmit_reinvite_with_sdp (struct sip_pvt *p, int t38version, int oldsdp)
 Transmit reinvite with SDP. More...
 
static int transmit_request (struct sip_pvt *p, int sipmethod, uint32_t seqno, enum xmittype reliable, int newbranch)
 Transmit generic SIP request returns XMIT_ERROR if transmit failed with a critical error (don't retry) More...
 
static int transmit_request_with_auth (struct sip_pvt *p, int sipmethod, uint32_t seqno, enum xmittype reliable, int newbranch)
 Transmit SIP request, auth added. More...
 
static int transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req)
 Transmit response, no retransmits. More...
 
static int transmit_response_reliable (struct sip_pvt *p, const char *msg, const struct sip_request *req)
 Transmit response, Make sure you get an ACK This is only used for responses to INVITEs, where we need to make sure we get an ACK. More...
 
static int transmit_response_using_temp (ast_string_field callid, struct ast_sockaddr *addr, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg)
 Transmit response, no retransmits, using a temporary pvt structure. More...
 
static int transmit_response_with_allow (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable)
 Append Accept header, content length before transmitting response. More...
 
static int transmit_response_with_auth (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *nonce, enum xmittype reliable, const char *header, int stale)
 Respond with authorization request. More...
 
static int transmit_response_with_date (struct sip_pvt *p, const char *msg, const struct sip_request *req)
 Add date before transmitting response. More...
 
static int transmit_response_with_minexpires (struct sip_pvt *p, const char *msg, const struct sip_request *req, int minexpires)
 Append Min-Expires header, content length before transmitting response. More...
 
static int transmit_response_with_minse (struct sip_pvt *p, const char *msg, const struct sip_request *req, int minse_int)
 Transmit 422 response with Min-SE header (Session-Timers)
More...
 
static int transmit_response_with_retry_after (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *seconds)
 Append Retry-After header field when transmitting response. More...
 
static int transmit_response_with_sdp (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable, int oldsdp, int rpid)
 Used for 200 OK and 183 early media. More...
 
static int transmit_response_with_sip_etag (struct sip_pvt *p, const char *msg, const struct sip_request *req, struct sip_esc_entry *esc_entry, int need_new_etag)
 
static int transmit_response_with_t38_sdp (struct sip_pvt *p, char *msg, struct sip_request *req, int retrans)
 Used for 200 OK and 183 early media. More...
 
static int transmit_response_with_unsupported (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *unsupported)
 Transmit response, no retransmits. More...
 
static int transmit_state_notify (struct sip_pvt *p, struct state_notify_data *data, int full, int timeout)
 Used in the SUBSCRIBE notification subsystem (RFC3265) More...
 
static const char * trust_id_outbound2str (int mode)
 
static void try_suggested_sip_codec (struct sip_pvt *p)
 Try setting the codecs suggested by the SIP_CODEC channel variable. More...
 
static int uac_sips_contact (struct sip_request *req)
 Determine if, as a UAC, we need to use a SIPS Contact. More...
 
static int uas_sips_contact (struct sip_request *req)
 Determine if, as a UAS, we need to use a SIPS Contact. More...
 
static void unlink_all_peers_from_tables (void)
 
static void unlink_marked_peers_from_tables (void)
 Unlink all marked peers from ao2 containers. More...
 
static void unlink_peers_from_tables (peer_unlink_flag_t flag)
 
static int unload_module (void)
 PBX unload module API. More...
 
static int update_call_counter (struct sip_pvt *fup, int event)
 update_call_counter: Handle call_limit for SIP devices Setting a call-limit will cause calls above the limit not to be accepted. More...
 
static void update_connectedline (struct sip_pvt *p, const void *data, size_t datalen)
 Notify peer that the connected line has changed. More...
 
static void update_peer (struct sip_peer *p, int expire)
 Update peer data in database (if used) More...
 
static void update_peer_lastmsgssent (struct sip_peer *peer, int value, int locked)
 
static void update_provisional_keepalive (struct sip_pvt *pvt, int with_sdp)
 
static void update_redirecting (struct sip_pvt *p, const void *data, size_t datalen)
 Send a provisional response indicating that a call was redirected. More...
 
static int use_reason_header (struct sip_pvt *pvt, struct sip_request *req)
 Parses SIP reason header according to RFC3326 and sets channel's hangupcause if configured so and header present. More...
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Session Initiation Protocol (SIP)" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_DEPRECATED, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CHANNEL_DRIVER, .requires = "ccss,dnsmgr,udptl", .optional_modules = "res_crypto,res_http_websocket", }
 
static struct stasis_subscriptionacl_change_sub
 
static const struct cfalias aliases []
 
static const struct _map_x_s allowoverlapstr []
 
static char * app_dtmfmode = "SIPDtmfMode"
 
static char * app_sipaddheader = "SIPAddHeader"
 
static char * app_sipremoveheader = "SIPRemoveHeader"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct sip_auth_containerauthl = NULL
 Authentication container for realm authentication. More...
 
static ast_mutex_t authl_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 Global authentication container protection while adjusting the references. More...
 
static int authlimit = DEFAULT_AUTHLIMIT
 
static int authtimeout = DEFAULT_AUTHTIMEOUT
 
static struct _map_x_s autopeermodes []
 
struct ast_sockaddr bindaddr
 
static const struct epa_static_data cc_epa_static_data
 
static const struct sip_esc_publish_callbacks cc_esc_publish_callbacks
 
static const struct ast_sip_api_tech chan_sip_api_provider
 
static struct ast_custom_function checksipdomain_function
 
static struct ast_cli_entry cli_sip []
 SIP Cli commands definition. More...
 
static const char config [] = "sip.conf"
 
static struct ast_sockaddr debugaddr
 
static struct ast_rtp_dtls_cfg default_dtls_cfg
 Default DTLS connection configuration. More...
 
static int default_expiry = DEFAULT_DEFAULT_EXPIRY
 
static struct ast_jb_conf default_jbconf
 Global jitterbuffer configuration - by default, jb is disabled. More...
 
static const int DEFAULT_PUBLISH_EXPIRES = 3600
 
static struct ast_tls_config default_tls_cfg
 Default TLS connection configuration. More...
 
static struct ao2_containerdialogs
 
struct ao2_containerdialogs_needdestroy
 
struct ao2_containerdialogs_rtpcheck
 
static struct domain_list domain_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static const struct _map_x_s dtmfstr []
 mapping between dtmf flags and strings More...
 
struct epa_static_data_list epa_static_data_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static int esc_etag_counter
 
static const int ESC_MAX_BUCKETS = 37
 
static struct event_state_compositor event_state_compositors []
 
static struct ast_sockaddr externaddr
 our external IP address/port for SIP sessions. externaddr.sin_addr is only set when we know we might be behind a NAT, and this is done using a variety of (mutually exclusive) ways from the config file: More...
 
static time_t externexpire
 
static char externhost [MAXHOSTNAMELEN]
 
static int externrefresh = 10
 
static uint16_t externtcpport
 
static uint16_t externtlsport
 
static struct _map_x_s faxecmodes []
 
static struct ast_flags global_flags [3] = {{0}}
 
static struct ast_jb_conf global_jbconf
 
static unsigned int global_t38_maxdatagram
 
static const int HASH_DIALOG_SIZE = 563
 
static const int HASH_PEER_SIZE = 563
 
static const int HASH_REGISTRY_SIZE = 563
 
static const struct _map_x_s insecurestr []
 
static struct ast_sockaddr internip
 our (internal) default address/port to put in SIP/SDP messages internip is initialized picking a suitable address from one of the interfaces, and the same port number we bind to. It is used as the default address/port in SIP messages, and as the default address (but not port) in SDP messages. More...
 
static const struct invstate2stringtable invitestate2string []
 
static struct io_contextio
 
static struct ast_halocaladdr
 List of local networks We store "localnet" addresses from the config file into an access list, marked as 'DENY', so the call to ast_apply_ha() will return AST_SENSE_DENY for 'local' addresses, and AST_SENSE_ALLOW for 'non local' (i.e. presumably public) addresses. More...
 
static int log_level = -1
 
static int max_expiry = DEFAULT_MAX_EXPIRY
 
static int max_subexpiry = DEFAULT_MAX_EXPIRY
 
static struct ast_sockaddr media_address
 
static int min_expiry = DEFAULT_MIN_EXPIRY
 
static int min_subexpiry = DEFAULT_MIN_EXPIRY
 
static pthread_t monitor_thread = AST_PTHREADT_NULL
 This is the thread for the monitor which checks for input on the channels which are not currently in use.
More...
 
static ast_mutex_t monlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical. More...
 
static int mwi_expiry = DEFAULT_MWI_EXPIRY
 
static ast_mutex_t netlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static int network_change_sched_id = -1
 
static struct stasis_subscriptionnetwork_change_sub
 
static const char notify_config [] = "sip_notify.conf"
 
static struct ast_confignotify_types = NULL
 
static int ourport_tcp
 
static int ourport_tls
 
static struct ao2_containerpeers
 The peer list: Users, Peers and Friends. More...
 
static struct ao2_containerpeers_by_ip
 
static const struct _map_x_s referstatusstrings []
 
static struct ao2_containerregistry_list
 The register list: Other SIP proxies we register with and receive calls from. More...
 
static const struct _map_x_s regstatestrings []
 
static struct ast_sockaddr rtpbindaddr
 
struct ast_sched_contextsched
 
static struct ast_cc_agent_callbacks sip_cc_agent_callbacks
 
static struct ast_cc_monitor_callbacks sip_cc_monitor_callbacks
 
struct {
   enum sip_cc_notify_state   state
 
   const char *   state_string
 
sip_cc_notify_state_map []
 
struct {
   enum ast_cc_service_type   service
 
   const char *   service_string
 
sip_cc_service_map []
 
static struct ast_threadstorage sip_content_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_sip_content_buf , .custom_init = NULL , }
 
static struct ast_custom_function sip_header_function
 
static struct ast_custom_function sip_headers_function
 
static const struct cfsip_methods sip_methods []
 
struct ao2_containersip_monitor_instances
 
static const struct ast_msg_tech sip_msg_tech
 
static const struct sip_reasons sip_reason_table []
 
static ast_mutex_t sip_reload_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static int sip_reloading = FALSE
 
static enum channelreloadreason sip_reloadreason
 
static struct ast_rtp_glue sip_rtp_glue
 
static struct ast_tcptls_session_args sip_tcp_desc
 The TCP server definition. More...
 
struct ast_channel_tech sip_tech
 Definition of this channel for PBX channel registration. More...
 
struct ast_channel_tech sip_tech_info
 This version of the sip channel tech has no send_digit_begin callback so that the core knows that the channel does not want DTMF BEGIN frames. The struct is initialized just before registering the channel driver, and is for use with channels using SIP INFO DTMF. More...
 
static struct ast_tls_config sip_tls_cfg
 Working TLS connection configuration. More...
 
static struct ast_tcptls_session_args sip_tls_desc
 The TCP/TLS server definition. More...
 
static struct ast_threadstorage sip_transport_str_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_sip_transport_str_buf , .custom_init = NULL , }
 
static enum sip_debug_e sipdebug
 
static int sipdebug_text
 extra debugging for 'text' related events. At the moment this is set together with sip_debug_console. More...
 
static struct ast_custom_function sippeer_function
 Structure to declare a dialplan function: SIPPEER. More...
 
static int sipsock = -1
 Main socket for UDP SIP communication. More...
 
static int * sipsock_read_id
 
static const struct _map_x_s stmodes []
 Report Peer status in character string. More...
 
static const struct _map_x_s strefresher_params []
 
static const struct _map_x_s strefreshers []
 
static struct ao2_containersubscription_mwi_list
 The MWI subscription list. More...
 
static const struct cfsubscription_types subscription_types []
 
static struct ao2_containerthreadt
 The table of TCP threads. More...
 
static const struct _map_x_s trust_id_outboundstr []
 
static struct ast_threadstorage ts_temp_pvt = { .once = PTHREAD_ONCE_INIT , .key_init = __init_ts_temp_pvt , .custom_init = temp_pvt_init , }
 
static int unauth_sessions = 0
 
static char used_context [AST_MAX_CONTEXT]
 
Object counters @{
Bug:
These counters are not handled in a thread-safe way ast_atomic_fetchadd_int() should be used to modify these values.
static int apeerobjs = 0
 
static int rpeerobjs = 0
 
static int speerobjs = 0
 

DefaultSettings

Default setttings are used as a channel setting and as a default when configuring devices

static int can_parse_xml
 
static unsigned int chan_idx
 
static char default_callerid [AST_MAX_EXTENSION]
 
static char default_engine [256]
 
static char default_fromdomain [AST_MAX_EXTENSION]
 
static int default_fromdomainport
 
static int default_keepalive
 
static char default_language [MAX_LANGUAGE]
 
static int default_maxcallbitrate
 
static char default_mohinterpret [MAX_MUSICCLASS]
 
static char default_mohsuggest [MAX_MUSICCLASS]
 
static char default_mwi_from [80]
 
static char default_notifymime [AST_MAX_EXTENSION]
 
static char default_parkinglot [AST_MAX_CONTEXT]
 
static unsigned int default_primary_transport
 
static int default_qualify
 
static unsigned int default_transports
 
static char default_vmexten [AST_MAX_EXTENSION]
 
static char default_zone [MAX_TONEZONE_COUNTRY]
 
static unsigned int dumphistory
 
static int global_authfailureevents
 
static unsigned int global_autoframing
 
static int global_callcounter
 
static unsigned int global_cos_audio
 
static unsigned int global_cos_sip
 
static unsigned int global_cos_text
 
static unsigned int global_cos_video
 
static int global_dynamic_exclude_static = 0
 
static int global_match_auth_username
 
static int global_max_se
 
static int global_min_se
 
static int global_prematuremediafilter
 
static int global_qualify_gap
 
static int global_qualify_peers
 
static int global_qualifyfreq
 
static unsigned char global_refer_addheaders
 
static int global_reg_retry_403
 
static int global_reg_timeout
 
static int global_regattempts_max
 
static int global_relaxdtmf
 
static int global_rtpholdtimeout
 
static int global_rtpkeepalive
 
static int global_rtptimeout
 
static char global_sdpowner [AST_MAX_EXTENSION]
 
static char global_sdpsession [AST_MAX_EXTENSION]
 
static int global_shrinkcallerid
 
static enum st_mode global_st_mode
 
static enum st_refresher_param global_st_refresher
 
static int global_store_sip_cause
 
static int global_t1
 
static int global_t1min
 
static int global_timer_b
 
static unsigned int global_tos_audio
 
static unsigned int global_tos_sip
 
static unsigned int global_tos_text
 
static unsigned int global_tos_video
 
static char global_useragent [AST_MAX_EXTENSION]
 
static unsigned int recordhistory
 
static struct sip_settings sip_cfg
 
#define SIP_PEDANTIC_DECODE(str)
 

Detailed Description

Implementation of Session Initiation Protocol.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

See Also:

Implementation of RFC 3261 - without S/MIME, and experimental TCP and TLS support Configuration file Config_sip

********** IMPORTANT *

Note
TCP/TLS support is EXPERIMENTAL and WILL CHANGE. This applies to configuration settings, dialplan commands and dialplans apps/functions See SIP TCP and TLS support

******** General TODO:s

Todo:

Better support of forking

VIA branch tag transaction checking

Transaction support

******** Wishlist: Improvements

Overview of the handling of SIP sessions
The SIP channel handles several types of SIP sessions, or dialogs, not all of them being "telephone calls".
  • Incoming calls that will be sent to the PBX core
  • Outgoing calls, generated by the PBX
  • SIP subscriptions and notifications of states and voicemail messages
  • SIP registrations, both inbound and outbound
  • SIP peer management (peerpoke, OPTIONS)
  • SIP text messages

In the SIP channel, there's a list of active SIP dialogs, which includes all of these when they are active. "sip show channels" in the CLI will show most of these, excluding subscriptions which are shown by "sip show subscriptions"

incoming packets
Incoming packets are received in the monitoring thread, then handled by sipsock_read() for udp only. In tcp, packets are read by the tcp_helper thread. sipsock_read() function parses the packet and matches an existing dialog or starts a new SIP dialog.

sipsock_read sends the packet to handle_incoming(), that parses a bit more. If it is a response to an outbound request, the packet is sent to handle_response(). If it is a request, handle_incoming() sends it to one of a list of functions depending on the request type - INVITE, OPTIONS, REFER, BYE, CANCEL etc sipsock_read locks the ast_channel if it exists (an active call) and unlocks it after we have processed the SIP message.

A new INVITE is sent to handle_request_invite(), that will end up starting a new channel in the PBX, the new channel after that executing in a separate channel thread. This is an incoming "call". When the call is answered, either by a bridged channel or the PBX itself the sip_answer() function is called.

The actual media - Video or Audio - is mostly handled by the RTP subsystem in rtp.c

Outbound calls
Outbound calls are set up by the PBX through the sip_request_call() function. After that, they are activated by sip_call().
Hanging up
The PBX issues a hangup on both incoming and outgoing calls through the sip_hangup() function

Definition in file chan_sip.c.

Macro Definition Documentation

◆ append_history

#define append_history (   p,
  event,
  fmt,
  args... 
)    append_history_full(p, "%-15s " fmt, event, ## args)

Append to SIP dialog history.

Return values
0always

Definition at line 2410 of file chan_sip.c.

◆ BOGUS_PEER_MD5SECRET

#define BOGUS_PEER_MD5SECRET   "intentionally_invalid_md5_string"

We can recognize the bogus peer by this invalid MD5 hash.

Definition at line 1062 of file chan_sip.c.

◆ check_request_transport

#define check_request_transport (   peer,
  tmpl 
)

generic function for determining if a correct transport is being used to contact a peer

this is done as a macro so that the "tmpl" var can be passed either a sip_request or a sip_peer

Definition at line 2502 of file chan_sip.c.

◆ CONTAINER_UNLINK

#define CONTAINER_UNLINK (   container,
  obj,
  tag 
)

Unlink the given object from the container and return TRUE if it was in the container.

Definition at line 8848 of file chan_sip.c.

◆ find_call

#define find_call (   req,
  addr,
  intended_method 
)     __find_call(req, addr, intended_method, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Definition at line 1244 of file chan_sip.c.

◆ FORMAT [1/8]

#define FORMAT   "%-25.25s %-15.15s %-15.15s \n"

Definition at line 22161 of file chan_sip.c.

◆ FORMAT [2/8]

#define FORMAT   "%-47.47s %-9.9s %-6.6s\n"

Definition at line 22161 of file chan_sip.c.

◆ FORMAT [3/8]

#define FORMAT   "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n"

Definition at line 22161 of file chan_sip.c.

◆ FORMAT [4/8]

#define FORMAT   "%-40.40s %-20.20s %-16.16s\n"

Definition at line 22161 of file chan_sip.c.

◆ FORMAT [5/8]

#define FORMAT   "%-39.39s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n"

Definition at line 22161 of file chan_sip.c.

◆ FORMAT [6/8]

#define FORMAT   "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf\n"

Definition at line 22161 of file chan_sip.c.

◆ FORMAT [7/8]

#define FORMAT   "%-30.30s %-12.12s %-10.10s %-10.10s\n"

Definition at line 22161 of file chan_sip.c.

◆ FORMAT [8/8]

#define FORMAT   "%-15.15s %-15.15s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s %-10.10s\n"

Definition at line 22161 of file chan_sip.c.

◆ FORMAT2 [1/5]

#define FORMAT2   "%-25.25s %-15.15s %-15.15s \n"

Definition at line 22160 of file chan_sip.c.

◆ FORMAT2 [2/5]

#define FORMAT2   "%-47.47s %9.9s %6.6s\n"

Definition at line 22160 of file chan_sip.c.

◆ FORMAT2 [3/5]

#define FORMAT2   "%-39.39s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n"

Definition at line 22160 of file chan_sip.c.

◆ FORMAT2 [4/5]

#define FORMAT2   "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n"

Definition at line 22160 of file chan_sip.c.

◆ FORMAT2 [5/5]

#define FORMAT2   "%-15.15s %-15.15s %-15.15s %-15.15s %-7.7s %-15.15s %-10.10s %-10.10s\n"

Definition at line 22160 of file chan_sip.c.

◆ FORMAT3

#define FORMAT3   "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6s\n"

Definition at line 22159 of file chan_sip.c.

◆ FORMAT4

#define FORMAT4   "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6d\n"

Definition at line 22158 of file chan_sip.c.

◆ peer_in_destruction

#define peer_in_destruction (   peer)    (ao2_ref(peer, 0) == 0)

Definition at line 1341 of file chan_sip.c.

◆ PEERS_FORMAT2

#define PEERS_FORMAT2   "%-25.25s %-39.39s %-3.3s %-10.10s %-10.10s %-3.3s %-8s %-11s %-32.32s %s\n"

Definition at line 20289 of file chan_sip.c.

◆ REMOVE_MAILBOX_WITH_LOCKED_PEER

#define REMOVE_MAILBOX_WITH_LOCKED_PEER (   __peer)

Definition at line 5291 of file chan_sip.c.

◆ SIP_PEDANTIC_DECODE

#define SIP_PEDANTIC_DECODE (   str)
Value:
ast_uri_decode(str, ast_uri_sip_user); \
} \
const char * str
Definition: app_jack.c:147
static struct sip_settings sip_cfg
Definition: chan_sip.c:813
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int pedanticsipchecking
Definition: sip.h:749
const struct ast_flags ast_uri_sip_user
Definition: main/utils.c:575

Definition at line 817 of file chan_sip.c.

◆ sip_pvt_lock

#define sip_pvt_lock (   x)    ao2_lock(x)

Definition at line 1048 of file chan_sip.c.

◆ sip_pvt_trylock

#define sip_pvt_trylock (   x)    ao2_trylock(x)

Definition at line 1049 of file chan_sip.c.

◆ sip_pvt_unlock

#define sip_pvt_unlock (   x)    ao2_unlock(x)

Definition at line 1050 of file chan_sip.c.

◆ SIP_TRANSPORT_STR_BUFSIZE

#define SIP_TRANSPORT_STR_BUFSIZE   128

Size of the SIP transport buffer.

Definition at line 1080 of file chan_sip.c.

◆ SIPHEADER

#define SIPHEADER   256

◆ UNLINK

#define UNLINK (   element,
  head,
  prev 
)

some list management macros.

Definition at line 1161 of file chan_sip.c.

Enumeration Type Documentation

◆ match_req_res

Enumerator
SIP_REQ_MATCH 
SIP_REQ_NOT_MATCH 
SIP_REQ_LOOP_DETECTED 
SIP_REQ_FORKED 

Definition at line 9173 of file chan_sip.c.

9173  {
9174  SIP_REQ_MATCH,
9176  SIP_REQ_LOOP_DETECTED, /* multiple incoming requests with same call-id but different branch parameters have been detected */
9177  SIP_REQ_FORKED, /* An outgoing request has been forked as result of receiving two differing 200ok responses. */
9178 };
@ SIP_REQ_FORKED
Definition: chan_sip.c:9177
@ SIP_REQ_MATCH
Definition: chan_sip.c:9174
@ SIP_REQ_LOOP_DETECTED
Definition: chan_sip.c:9176
@ SIP_REQ_NOT_MATCH
Definition: chan_sip.c:9175

◆ message_integrity

Indication of a TCP message's integrity.

Enumerator
MESSAGE_INVALID 

The message has an error in it with regards to its Content-Length header

MESSAGE_FRAGMENT 

The message is incomplete

MESSAGE_FRAGMENT_COMPLETE 

The data contains a complete message plus a fragment of another.

MESSAGE_COMPLETE 

The message is complete

Definition at line 2765 of file chan_sip.c.

2765  {
2766  /*!
2767  * The message has an error in it with
2768  * regards to its Content-Length header
2769  */
2771  /*!
2772  * The message is incomplete
2773  */
2775  /*!
2776  * The data contains a complete message
2777  * plus a fragment of another.
2778  */
2780  /*!
2781  * The message is complete
2782  */
2784 };
@ MESSAGE_FRAGMENT_COMPLETE
Definition: chan_sip.c:2779
@ MESSAGE_COMPLETE
Definition: chan_sip.c:2783
@ MESSAGE_INVALID
Definition: chan_sip.c:2770
@ MESSAGE_FRAGMENT
Definition: chan_sip.c:2774

◆ peer_unlink_flag_t

Enumerator
SIP_PEERS_MARKED 
SIP_PEERS_ALL 

Definition at line 3231 of file chan_sip.c.

3231  {
3233  SIP_PEERS_ALL,
peer_unlink_flag_t
Definition: chan_sip.c:3231
@ SIP_PEERS_ALL
Definition: chan_sip.c:3233
@ SIP_PEERS_MARKED
Definition: chan_sip.c:3232

◆ sip_media_fds

Enumerator
SIP_AUDIO_RTP_FD 
SIP_AUDIO_RTCP_FD 
SIP_VIDEO_RTP_FD 
SIP_VIDEO_RTCP_FD 
SIP_TEXT_RTP_FD 
SIP_UDPTL_FD 

Definition at line 7851 of file chan_sip.c.

7851  {
7857  SIP_UDPTL_FD,
7858 };
@ SIP_UDPTL_FD
Definition: chan_sip.c:7857
@ SIP_VIDEO_RTCP_FD
Definition: chan_sip.c:7855
@ SIP_VIDEO_RTP_FD
Definition: chan_sip.c:7854
@ SIP_TEXT_RTP_FD
Definition: chan_sip.c:7856
@ SIP_AUDIO_RTP_FD
Definition: chan_sip.c:7852
@ SIP_AUDIO_RTCP_FD
Definition: chan_sip.c:7853

Function Documentation

◆ __cleanup_registration()

static int __cleanup_registration ( const void *  data)
static

Definition at line 32465 of file chan_sip.c.

32466 {
32467  struct sip_registry *reg = (struct sip_registry *) data;
32468 
32469  ao2_lock(reg);
32470 
32471  if (reg->call) {
32472  ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname);
32473  /* This will also remove references to the registry */
32474  dialog_unlink_all(reg->call);
32475  reg->call = dialog_unref(reg->call, "remove iterator->call from registry traversal");
32476  }
32477 
32479  ao2_t_ref(reg, -1, "Stop scheduled reregister timeout"));
32481  ao2_t_ref(reg, -1, "Stop scheduled register timeout"));
32482 
32483  if (reg->dnsmgr) {
32484  ast_dnsmgr_release(reg->dnsmgr);
32485  reg->dnsmgr = NULL;
32486  ao2_t_ref(reg, -1, "reg ptr unref from dnsmgr");
32487  }
32488 
32489  ao2_unlock(reg);
32490 
32491  ao2_t_ref(reg, -1, "cleanup_registration action");
32492  return 0;
32493 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ao2_lock(a)
Definition: astobj2.h:718
void dialog_unlink_all(struct sip_pvt *dialog)
Unlink a dialog from the dialogs container, as well as any other places that it may be currently stor...
Definition: chan_sip.c:3374
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
Free a DNS manager entry.
Definition: dnsmgr.c:136
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:453
#define NULL
Definition: resample.c:96
#define AST_SCHED_DEL_UNREF(sched, id, refcall)
schedule task to get deleted and call unref function
Definition: sched.h:80
Definition: sched.c:76
Registrations with other SIP proxies.
Definition: sip.h:1389
struct ast_dnsmgr_entry * dnsmgr
Definition: sip.h:1422
int expire
Definition: sip.h:1411
int timeout
Definition: sip.h:1415
const ast_string_field username
Definition: sip.h:1407
struct sip_pvt * call
Definition: sip.h:1417
const ast_string_field hostname
Definition: sip.h:1407

References ao2_lock, ao2_t_ref, ao2_unlock, ast_debug, ast_dnsmgr_release(), AST_SCHED_DEL_UNREF, sip_registry::call, dialog_unlink_all(), dialog_unref, sip_registry::dnsmgr, sip_registry::expire, sip_registry::hostname, NULL, sip_registry::timeout, and sip_registry::username.

Referenced by cleanup_registration().

◆ __dialog_unlink_sched_items()

static int __dialog_unlink_sched_items ( const void *  data)
static

Definition at line 3358 of file chan_sip.c.

3359 {
3360  struct sip_pvt *dialog = (void *) data;
3361 
3363  dialog_unref(dialog, "Stop scheduled items for unlink action");
3364  return 0;
3365 }
static void do_dialog_unlink_sched_items(struct sip_pvt *dialog)
Definition: chan_sip.c:3315
Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized ...
Definition: sip.h:998

References dialog_unref, and do_dialog_unlink_sched_items().

Referenced by dialog_unlink_all().

◆ __find_call()

static struct sip_pvt * __find_call ( struct sip_request req,
struct ast_sockaddr addr,
const int  intended_method,
const char *  file,
int  line,
const char *  func 
)
static

find or create a dialog structure for an incoming SIP message. Connect incoming SIP message to current dialog or create new dialog structure Returns a reference to the sip_pvt object, remember to give it back once done. Called by handle_request_do

Definition at line 9477 of file chan_sip.c.

9479 {
9480  char totag[128];
9481  char fromtag[128];
9482  const char *callid = sip_get_header(req, "Call-ID");
9483  const char *from = sip_get_header(req, "From");
9484  const char *to = sip_get_header(req, "To");
9485  const char *cseq = sip_get_header(req, "Cseq");
9486  struct sip_pvt *sip_pvt_ptr;
9487  uint32_t seqno;
9488  /* Call-ID, to, from and Cseq are required by RFC 3261. (Max-forwards and via too - ignored now) */
9489  /* sip_get_header always returns non-NULL so we must use ast_strlen_zero() */
9490  if (ast_strlen_zero(callid) || ast_strlen_zero(to) ||
9491  ast_strlen_zero(from) || ast_strlen_zero(cseq) ||
9492  (sscanf(cseq, "%30u", &seqno) != 1)) {
9493 
9494  /* RFC 3261 section 24.4.1. Send a 400 Bad Request if the request is malformed. */
9495  if (intended_method != SIP_RESPONSE && intended_method != SIP_ACK) {
9496  transmit_response_using_temp(callid, addr, 1, intended_method,
9497  req, "400 Bad Request");
9498  }
9499  return NULL; /* Invalid packet */
9500  }
9501 
9503  /* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy
9504  we need more to identify a branch - so we have to check branch, from
9505  and to tags to identify a call leg.
9506  For Asterisk to behave correctly, you need to turn on pedanticsipchecking
9507  in sip.conf
9508  */
9509  if (gettag(req, "To", totag, sizeof(totag)))
9510  req->has_to_tag = 1; /* Used in handle_request/response */
9511  gettag(req, "From", fromtag, sizeof(fromtag));
9512 
9513  ast_debug(5, "= Looking for Call ID: %s (Checking %s) --From tag %s --To-tag %s \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag);
9514 
9515  /* All messages must always have From: tag */
9516  if (ast_strlen_zero(fromtag)) {
9517  ast_debug(5, "%s request has no from tag, dropping callid: %s from: %s\n", sip_methods[req->method].text , callid, from );
9518  return NULL;
9519  }
9520  /* reject requests that must always have a To: tag */
9521  if (ast_strlen_zero(totag) && (req->method == SIP_ACK || req->method == SIP_BYE || req->method == SIP_INFO )) {
9522  if (req->method != SIP_ACK) {
9523  transmit_response_using_temp(callid, addr, 1, intended_method, req, "481 Call leg/transaction does not exist");
9524  }
9525  ast_debug(5, "%s must have a to tag. dropping callid: %s from: %s\n", sip_methods[req->method].text , callid, from );
9526  return NULL;
9527  }
9528  }
9529 
9530  /* match on callid only for REGISTERs */
9531  if (!sip_cfg.pedanticsipchecking || req->method == SIP_REGISTER) {
9532  struct sip_pvt tmp_dialog = {
9533  .callid = callid,
9534  };
9535  sip_pvt_ptr = __ao2_find(dialogs, &tmp_dialog, OBJ_POINTER,
9536  "find_call in dialogs", file, line, func);
9537  if (sip_pvt_ptr) { /* well, if we don't find it-- what IS in there? */
9538  /* Found the call */
9539  return sip_pvt_ptr;
9540  }
9541  } else { /* in pedantic mode! -- do the fancy search */
9542  struct sip_pvt tmp_dialog = {
9543  .callid = callid,
9544  };
9545  /* if a Outbound forked Request is detected, this pvt will point
9546  * to the dialog the Request is forking off of. */
9547  struct sip_pvt *fork_pvt = NULL;
9548  struct match_req_args args = { 0, };
9549  int found;
9550  struct ao2_iterator *iterator = __ao2_callback(dialogs,
9553  &tmp_dialog,
9554  "pedantic ao2_find in dialogs",
9555  file, line, func);
9556  struct sip_via *via = NULL;
9557 
9558  args.method = req->method;
9559  args.callid = NULL; /* we already matched this. */
9560  args.totag = totag;
9561  args.fromtag = fromtag;
9562  args.seqno = seqno;
9563  /* get via header information. */
9564  args.ruri = REQ_OFFSET_TO_STR(req, rlpart2);
9565  via = parse_via(sip_get_header(req, "Via"));
9566  if (via) {
9567  args.viasentby = via->sent_by;
9568  args.viabranch = via->branch;
9569  }
9570  /* determine if this is a Request with authentication credentials. */
9571  if (!ast_strlen_zero(sip_get_header(req, "Authorization")) ||
9572  !ast_strlen_zero(sip_get_header(req, "Proxy-Authorization"))) {
9573  args.authentication_present = 1;
9574  }
9575  /* if it is a response, get the response code */
9576  if (req->method == SIP_RESPONSE) {
9577  const char* e = ast_skip_blanks(REQ_OFFSET_TO_STR(req, rlpart2));
9578  int respid;
9579  if (!ast_strlen_zero(e) && (sscanf(e, "%30d", &respid) == 1)) {
9580  args.respid = respid;
9581  }
9582  }
9583 
9584  /* Iterate a list of dialogs already matched by Call-id */
9585  while (iterator && (sip_pvt_ptr = ao2_iterator_next(iterator))) {
9586  sip_pvt_lock(sip_pvt_ptr);
9587  found = match_req_to_dialog(sip_pvt_ptr, &args);
9588  sip_pvt_unlock(sip_pvt_ptr);
9589 
9590  switch (found) {
9591  case SIP_REQ_MATCH:
9592  sip_pvt_lock(sip_pvt_ptr);
9593  if (args.method != SIP_RESPONSE && args.authentication_present
9594  && strcmp(args.fromtag, sip_pvt_ptr->theirtag)) {
9595  /* If we have a request that uses athentication and the fromtag is
9596  * different from that in the original call dialog, update the
9597  * fromtag in the saved call dialog */
9598  ast_string_field_set(sip_pvt_ptr, theirtag, args.fromtag);
9599  }
9600  sip_pvt_unlock(sip_pvt_ptr);
9601  ao2_iterator_destroy(iterator);
9602  dialog_unref(fork_pvt, "unref fork_pvt");
9603  free_via(via);
9604  return sip_pvt_ptr; /* return pvt with ref */
9605  case SIP_REQ_LOOP_DETECTED:
9606  /* This is likely a forked Request that somehow resulted in us receiving multiple parts of the fork.
9607  * RFC 3261 section 8.2.2.2, Indicate that we want to merge requests by sending a 482 response. */
9608  transmit_response_using_temp(callid, addr, 1, intended_method, req, "482 (Loop Detected)");
9609  __ao2_ref(sip_pvt_ptr, -1, "pvt did not match incoming SIP msg, unref from search.",
9610  file, line, func);
9611  ao2_iterator_destroy(iterator);
9612  dialog_unref(fork_pvt, "unref fork_pvt");
9613  free_via(via);
9614  return NULL;
9615  case SIP_REQ_FORKED:
9616  dialog_unref(fork_pvt, "throwing way pvt to fork off of.");
9617  fork_pvt = dialog_ref(sip_pvt_ptr, "this pvt has a forked request, save this off to copy information into new dialog\n");
9618  /* fall through */
9619  case SIP_REQ_NOT_MATCH:
9620  default:
9621  __ao2_ref(sip_pvt_ptr, -1, "pvt did not match incoming SIP msg, unref from search",
9622  file, line, func);
9623  break;
9624  }
9625  }
9626  if (iterator) {
9627  ao2_iterator_destroy(iterator);
9628  }
9629 
9630  /* Handle any possible forked requests. This must be done only after transaction matching is complete. */
9631  if (fork_pvt) {
9632  /* XXX right now we only support handling forked INVITE Requests. Any other
9633  * forked request type must be added here. */
9634  if (fork_pvt->method == SIP_INVITE) {
9635  forked_invite_init(req, args.totag, fork_pvt, addr);
9636  dialog_unref(fork_pvt, "throwing way old forked pvt");
9637  free_via(via);
9638  return NULL;
9639  }
9640  fork_pvt = dialog_unref(fork_pvt, "throwing way pvt to fork off of");
9641  }
9642 
9643  free_via(via);
9644  } /* end of pedantic mode Request/Reponse to Dialog matching */
9645 
9646  /* See if the method is capable of creating a dialog */
9647  if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) {
9648  struct sip_pvt *p = NULL;
9650 
9651  if (intended_method == SIP_INVITE) {
9653  }
9654 
9655  /* Ok, time to create a new SIP dialog object, a pvt */
9656  if (!(p = sip_alloc(callid, addr, 1, intended_method, req, logger_callid))) {
9657  /* We have a memory or file/socket error (can't allocate RTP sockets or something) so we're not
9658  getting a dialog from sip_alloc.
9659 
9660  Without a dialog we can't retransmit and handle ACKs and all that, but at least
9661  send an error message.
9662 
9663  Sorry, we apologize for the inconvenience
9664  */
9665  transmit_response_using_temp(callid, addr, 1, intended_method, req, "500 Server internal error");
9666  ast_debug(4, "Failed allocating SIP dialog, sending 500 Server internal error and giving up\n");
9667  }
9668  return p; /* can be NULL */
9669  } else if( sip_methods[intended_method].can_create == CAN_CREATE_DIALOG_UNSUPPORTED_METHOD) {
9670  /* A method we do not support, let's take it on the volley */
9671  transmit_response_using_temp(callid, addr, 1, intended_method, req, "501 Method Not Implemented");
9672  ast_debug(2, "Got a request with unsupported SIP method.\n");
9673  } else if (intended_method != SIP_RESPONSE && intended_method != SIP_ACK) {
9674  /* This is a request outside of a dialog that we don't know about */
9675  transmit_response_using_temp(callid, addr, 1, intended_method, req, "481 Call leg/transaction does not exist");
9676  ast_debug(2, "That's odd... Got a request in unknown dialog. Callid %s\n", callid ? callid : "<unknown>");
9677  }
9678  /* We do not respond to responses for dialogs that we don't know about, we just drop
9679  the session quickly */
9680  if (intended_method == SIP_RESPONSE)
9681  ast_debug(2, "That's odd... Got a response on a call we don't know about. Callid %s\n", callid ? callid : "<unknown>");
9682 
9683  return NULL;
9684 }
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
#define OBJ_POINTER
Definition: astobj2.h:1154
void * __ao2_callback(struct ao2_container *c, enum search_flags flags, ao2_callback_fn *cb_fn, void *arg, const char *tag, const char *file, int line, const char *func)
void * __ao2_find(struct ao2_container *c, const void *arg, enum search_flags flags, const char *tag, const char *file, int line, const char *func)
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
@ OBJ_MULTIPLE
Definition: astobj2.h:1053
static void forked_invite_init(struct sip_request *req, const char *new_theirtag, struct sip_pvt *original, struct ast_sockaddr *addr)
This function creates a dialog to handle a forked request. This dialog exists only to properly termin...
Definition: chan_sip.c:9341
static int transmit_response_using_temp(ast_string_field callid, struct ast_sockaddr *addr, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg)
Transmit response, no retransmits, using a temporary pvt structure.
Definition: chan_sip.c:12610
#define sip_pvt_lock(x)
Definition: chan_sip.c:1048
const char * sip_get_header(const struct sip_request *req, const char *name)
Get header from SIP request.
Definition: chan_sip.c:8610
#define sip_pvt_unlock(x)
Definition: chan_sip.c:1050
static const char * gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize)
Get tag from packet.
Definition: chan_sip.c:25661
static int dialog_find_multiple(void *obj, void *arg, int flags)
Definition: chan_sip.c:34639
static const struct cfsip_methods sip_methods[]
static struct ao2_container * dialogs
Definition: chan_sip.c:1047
static enum match_req_res match_req_to_dialog(struct sip_pvt *sip_pvt_ptr, struct match_req_args *arg)
Match a incoming Request/Response to a dialog.
Definition: chan_sip.c:9185
#define dialog_ref(dialog, tag)
when we create or delete references, make sure to use these functions so we keep track of the refcoun...
Definition: dialog.h:32
#define sip_alloc(callid, addr, useglobal_nat, intended_method, req, logger_callid)
Definition: dialog.h:39
ast_callid ast_create_callid(void)
factory function to create a new uniquely identifying callid.
Definition: logger.c:2040
unsigned int ast_callid
Definition: logger.h:88
struct sip_via * parse_via(const char *header)
Parse a Via header.
void free_via(struct sip_via *v)
Free parsed Via data.
#define REQ_OFFSET_TO_STR(req, offset)
given a sip_request and an offset, return the char * that resides there
Definition: sip.h:851
@ SIP_RESPONSE
Definition: sip.h:607
@ SIP_BYE
Definition: sip.h:614
@ SIP_INFO
Definition: sip.h:619
@ SIP_ACK
Definition: sip.h:612
@ SIP_REGISTER
Definition: sip.h:608
@ SIP_INVITE
Definition: sip.h:611
@ CAN_CREATE_DIALOG_UNSUPPORTED_METHOD
Definition: sip.h:593
@ CAN_CREATE_DIALOG
Definition: sip.h:592
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:157
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
char *const text
Definition: chan_sip.c:741
arguments used for Request/Response to matching
Definition: chan_sip.c:9154
ast_callid logger_callid
Definition: sip.h:1001
const ast_string_field theirtag
Definition: sip.h:1056
const ast_string_field callid
Definition: sip.h:1056
const ast_string_field from
Definition: sip.h:1056
int method
Definition: sip.h:1002
char has_to_tag
Definition: sip.h:831
int method
Definition: sip.h:826
Structure to store Via information.
Definition: sip.h:867
char * via
Definition: sip.h:868
const char * args

References __ao2_callback(), __ao2_find(), __ao2_ref(), ao2_iterator_destroy(), ao2_iterator_next, args, ast_create_callid(), ast_debug, ast_skip_blanks(), ast_string_field_set, ast_strlen_zero(), sip_via::branch, sip_pvt::callid, CAN_CREATE_DIALOG, CAN_CREATE_DIALOG_UNSUPPORTED_METHOD, dialog_find_multiple(), dialog_ref, dialog_unref, dialogs, make_ari_stubs::file, forked_invite_init(), free_via(), gettag(), sip_request::has_to_tag, match_req_to_dialog(), sip_request::method, sip_pvt::method, NULL, OBJ_MULTIPLE, OBJ_POINTER, parse_via(), sip_settings::pedanticsipchecking, REQ_OFFSET_TO_STR, sip_via::sent_by, SIP_ACK, sip_alloc, SIP_BYE, sip_cfg, sip_get_header(), SIP_INFO, SIP_INVITE, sip_methods, sip_pvt_lock, sip_pvt_unlock, SIP_REGISTER, SIP_REQ_FORKED, SIP_REQ_LOOP_DETECTED, SIP_REQ_MATCH, SIP_REQ_NOT_MATCH, SIP_RESPONSE, cfsip_methods::text, sip_pvt::theirtag, and transmit_response_using_temp().

◆ __get_header()

static const char * __get_header ( const struct sip_request req,
const char *  name,
int *  start 
)
static

Definition at line 8572 of file chan_sip.c.

8573 {
8574  /*
8575  * Technically you can place arbitrary whitespace both before and after the ':' in
8576  * a header, although RFC3261 clearly says you shouldn't before, and place just
8577  * one afterwards. If you shouldn't do it, what absolute idiot decided it was
8578  * a good idea to say you can do it, and if you can do it, why in the hell would.
8579  * you say you shouldn't.
8580  */
8581  const char *sname = find_alias(name, NULL);
8582  int x, len = strlen(name), slen = (sname ? 1 : 0);
8583  for (x = *start; x < req->headers; x++) {
8584  const char *header = REQ_OFFSET_TO_STR(req, header[x]);
8585  int smatch = 0, match = !strncasecmp(header, name, len);
8586  if (slen) {
8587  smatch = !strncasecmp(header, sname, slen);
8588  }
8589  if (match || smatch) {
8590  /* skip name */
8591  const char *r = header + (match ? len : slen );
8592  /* HCOLON has optional SP/HTAB; skip past those */
8593  while (*r == ' ' || *r == '\t') {
8594  ++r;
8595  }
8596  if (*r == ':') {
8597  *start = x+1;
8598  return ast_skip_blanks(r+1);
8599  }
8600  }
8601  }
8602 
8603  /* Don't return NULL, so sip_get_header is always a valid pointer */
8604  return "";
8605 }
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2312
static const char * find_alias(const char *name, const char *_default)
Find compressed SIP alias.
Definition: chan_sip.c:8544
static const char name[]
Definition: format_mp3.c:68
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int headers
Definition: sip.h:825

References ast_skip_blanks(), find_alias(), sip_request::headers, len(), match(), name, NULL, and REQ_OFFSET_TO_STR.

Referenced by build_path(), build_route(), copy_all_header(), copy_via_headers(), func_header_read(), handle_incoming(), handle_request_invite(), handle_request_subscribe(), handle_response_register(), reply_digest(), and sip_get_header().

◆ __init_sip_content_buf()

static void __init_sip_content_buf ( void  )
static

Definition at line 8617 of file chan_sip.c.

8621 {

◆ __init_sip_transport_str_buf()

static void __init_sip_transport_str_buf ( void  )
static

A per-thread buffer for transport to string conversion.

Definition at line 1077 of file chan_sip.c.

1161 { \

◆ __init_ts_temp_pvt()

static void __init_ts_temp_pvt ( void  )
static

A per-thread temporary pvt structure.

Definition at line 1074 of file chan_sip.c.

1161 { \

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 35934 of file chan_sip.c.

◆ __sched_check_pendings()

static int __sched_check_pendings ( const void *  data)
static

Definition at line 23794 of file chan_sip.c.

23795 {
23796  struct sip_pvt *pvt = (void *) data;
23797  struct ast_channel *owner;
23798 
23799  owner = sip_pvt_lock_full(pvt);
23800  check_pendings(pvt);
23801  if (owner) {
23802  ast_channel_unlock(owner);
23803  ast_channel_unref(owner);
23804  }
23805  sip_pvt_unlock(pvt);
23806 
23807  dialog_unref(pvt, "Check pending actions action");
23808  return 0;
23809 }
static void check_pendings(struct sip_pvt *p)
Check pending actions on SIP call.
Definition: chan_sip.c:23744
static struct ast_channel * sip_pvt_lock_full(struct sip_pvt *pvt)
Definition: chan_sip.c:9408
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2924
#define ast_channel_unlock(chan)
Definition: channel.h:2889
Main Channel structure associated with a channel.

References ast_channel_unlock, ast_channel_unref, check_pendings(), dialog_unref, sip_pvt_lock_full(), and sip_pvt_unlock.

Referenced by sched_check_pendings().

◆ __set_address_from_contact()

static int __set_address_from_contact ( const char *  fullcontact,
struct ast_sockaddr addr,
int  tcp 
)
static

Definition at line 16899 of file chan_sip.c.

16900 {
16901  char *hostport, *transport;
16902  char contact_buf[256];
16903  char *contact;
16904 
16905  /* Work on a copy */
16906  ast_copy_string(contact_buf, fullcontact, sizeof(contact_buf));
16907  contact = contact_buf;
16908 
16909  /*
16910  * We have only the part in <brackets> here so we just need to parse a SIP URI.
16911  *
16912  * Note: The outbound proxy could be using UDP between the proxy and Asterisk.
16913  * We still need to be able to send to the remote agent through the proxy.
16914  */
16915 
16916  if (parse_uri_legacy_check(contact, "sip:,sips:", &contact, NULL, &hostport,
16917  &transport)) {
16918  ast_log(LOG_WARNING, "Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact);
16919  }
16920 
16921  /* XXX This could block for a long time XXX */
16922  /* We should only do this if it's a name, not an IP */
16923  /* \todo - if there's no PORT number in contact - we are required to check NAPTR/SRV records
16924  to find transport, port address and hostname. If there's a port number, we have to
16925  assume that the hostport part is a host name and only look for an A/AAAA record in DNS.
16926  */
16927 
16928  /* If we took in an invalid URI, hostport may not have been initialized */
16929  /* ast_sockaddr_resolve requires an initialized hostport string. */
16930  if (ast_strlen_zero(hostport)) {
16931  ast_log(LOG_WARNING, "Invalid URI: parse_uri failed to acquire hostport\n");
16932  return -1;
16933  }
16934 
16935  if (ast_sockaddr_resolve_first_transport(addr, hostport, 0, get_transport_str2enum(transport))) {
16936  ast_log(LOG_WARNING, "Invalid host name in Contact: (can't "
16937  "resolve in DNS) : '%s'\n", hostport);
16938  return -1;
16939  }
16940 
16941  /* set port */
16942  if (!ast_sockaddr_port(addr)) {
16943  ast_sockaddr_set_port(addr,
16944  (get_transport_str2enum(transport) ==
16946  !strncasecmp(fullcontact, "sips", 4)) ?
16948  }
16949 
16950  return 0;
16951 }
#define ast_log
Definition: astobj2.c:42
static int get_transport_str2enum(const char *transport)
Return int representing a bit field of transport types found in const char *transport.
Definition: chan_sip.c:3665
static int parse_uri_legacy_check(char *uri, const char *scheme, char **user, char **pass, char **hostport, char **transport)
parse uri in a way that allows semicolon stripping if legacy mode is enabled
Definition: chan_sip.c:16887
static int ast_sockaddr_resolve_first_transport(struct ast_sockaddr *addr, const char *name, int flag, unsigned int transport)
Return the first entry from ast_sockaddr_resolve filtered by family of binddaddr.
Definition: chan_sip.c:34485
#define LOG_WARNING
Definition: logger.h:275
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
Definition: netsock2.h:521
@ AST_TRANSPORT_TLS
Definition: netsock2.h:62
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition: netsock2.h:537
#define STANDARD_SIP_PORT
Standard SIP unsecure port for UDP and TCP from RFC 3261. DO NOT CHANGE THIS.
Definition: sip.h:169
#define STANDARD_TLS_PORT
Standard SIP TLS port from RFC 3261. DO NOT CHANGE THIS.
Definition: sip.h:171
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

References ast_copy_string(), ast_log, ast_sockaddr_port, ast_sockaddr_resolve_first_transport(), ast_sockaddr_set_port, ast_strlen_zero(), AST_TRANSPORT_TLS, get_transport_str2enum(), LOG_WARNING, NULL, parse_uri_legacy_check(), STANDARD_SIP_PORT, and STANDARD_TLS_PORT.

Referenced by build_peer(), create_addr_from_peer(), parse_register_contact(), sip_poke_peer(), and sip_request_call().

◆ __shutdown_mwi_subscription()

static int __shutdown_mwi_subscription ( const void *  data)
static

Definition at line 14942 of file chan_sip.c.

14943 {
14944  struct sip_subscription_mwi *mwi = (void *) data;
14945 
14947  ao2_t_ref(mwi, -1, "Stop scheduled mwi resub"));
14948 
14949  if (mwi->dnsmgr) {
14950  ast_dnsmgr_release(mwi->dnsmgr);
14951  mwi->dnsmgr = NULL;
14952  ao2_t_ref(mwi, -1, "dnsmgr release");
14953  }
14954 
14955  ao2_t_ref(mwi, -1, "Shutdown MWI subscription action");
14956  return 0;
14957 }
Definition of an MWI subscription to another server.
Definition: sip.h:1447
struct ast_dnsmgr_entry * dnsmgr
Definition: sip.h:1460

References ao2_t_ref, ast_dnsmgr_release(), AST_SCHED_DEL_UNREF, sip_subscription_mwi::dnsmgr, NULL, and sip_subscription_mwi::resub.

Referenced by shutdown_mwi_subscription().

◆ __sip_ack()

int __sip_ack ( struct sip_pvt p,
uint32_t  seqno,
int  resp,
int  sipmethod 
)

Acknowledges receipt of a packet and stops retransmission called with p locked.

Definition at line 4578 of file chan_sip.c.

4579 {
4580  struct sip_pkt *cur, *prev = NULL;
4581  const char *msg = "Not Found"; /* used only for debugging */
4582  int res = FALSE;
4583 
4584  /* If we have an outbound proxy for this dialog, then delete it now since
4585  the rest of the requests in this dialog needs to follow the routing.
4586  If obforcing is set, we will keep the outbound proxy during the whole
4587  dialog, regardless of what the SIP rfc says
4588  */
4589  if (p->outboundproxy && !p->outboundproxy->force) {
4590  ref_proxy(p, NULL);
4591  }
4592 
4593  for (cur = p->packets; cur; prev = cur, cur = cur->next) {
4594  if (cur->seqno != seqno || cur->is_resp != resp) {
4595  continue;
4596  }
4597  if (cur->is_resp || cur->method == sipmethod) {
4598  res = TRUE;
4599  msg = "Found";
4600  if (!resp && (seqno == p->pendinginvite)) {
4601  ast_debug(1, "Acked pending invite %u\n", p->pendinginvite);
4602  p->pendinginvite = 0;
4603  }
4604  if (cur->retransid > -1) {
4605  if (sipdebug)
4606  ast_debug(4, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid);
4607  }
4608 
4609  /* Unlink and destroy the packet object. */
4610  UNLINK(cur, p->packets, prev);
4611  stop_retrans_pkt(cur);
4612  ao2_t_ref(cur, -1, "Packet retransmission list");
4613  break;
4614  }
4615  }
4616  ast_debug(1, "Stopping retransmission on '%s' of %s %u: Match %s\n",
4617  p->callid, resp ? "Response" : "Request", seqno, msg);
4618  return res;
4619 }
#define TRUE
Definition: app_minivm.c:525
#define FALSE
Definition: app_minivm.c:528
#define UNLINK(element, head, prev)
Definition: chan_sip.c:1161
static void stop_retrans_pkt(struct sip_pkt *pkt)
Definition: chan_sip.c:4258
static enum sip_debug_e sipdebug
Definition: chan_sip.c:920
static void ref_proxy(struct sip_pvt *pvt, struct sip_proxy *proxy)
Definition: chan_sip.c:3300
sipmethod
SIP Request methods known by Asterisk.
Definition: sip.h:605
sip packet - raw format for outbound packets that are sent or scheduled for transmission Packets are ...
Definition: sip.h:1224
char is_resp
Definition: sip.h:1229
int retransid
Definition: sip.h:1233
uint32_t seqno
Definition: sip.h:1228
int method
Definition: sip.h:1227
struct sip_pkt * next
Definition: sip.h:1225
int force
Definition: sip.h:720
struct sip_pkt * packets
Definition: sip.h:1170
struct sip_proxy * outboundproxy
Definition: sip.h:1105
uint32_t pendinginvite
Definition: sip.h:1140

References ao2_t_ref, ast_debug, sip_pvt::callid, FALSE, sip_proxy::force, sip_pkt::is_resp, sip_pkt::method, sip_pkt::next, NULL, sip_pvt::outboundproxy, sip_pvt::packets, sip_pvt::pendinginvite, ref_proxy(), sip_pkt::retransid, sip_pkt::seqno, sipdebug, stop_retrans_pkt(), TRUE, and UNLINK.

Referenced by __sip_pretend_ack(), handle_incoming(), handle_request_invite(), handle_request_publish(), and handle_response().

◆ __sip_alloc()

struct sip_pvt* __sip_alloc ( ast_string_field  callid,
struct ast_sockaddr addr,
int  useglobal_nat,
const int  intended_method,
struct sip_request req,
ast_callid  logger_callid,
const char *  file,
int  line,
const char *  func 
)

Allocate sip_pvt structure, set defaults and link in the container. Returns a reference to the object so whoever uses it later must remember to release the reference.

Definition at line 8950 of file chan_sip.c.

8953 {
8954  struct sip_pvt *p;
8955 
8956  p = __ao2_alloc(sizeof(*p), sip_pvt_dtor,
8957  AO2_ALLOC_OPT_LOCK_MUTEX, "allocate a dialog(pvt) struct",
8958  file, line, func);
8959  if (!p) {
8960  return NULL;
8961  }
8962 
8963  if (ast_string_field_init(p, 512)) {
8964  ao2_t_ref(p, -1, "failed to string_field_init, drop p");
8965  return NULL;
8966  }
8967 
8968  if (!(p->cc_params = ast_cc_config_params_init())) {
8969  ao2_t_ref(p, -1, "Yuck, couldn't allocate cc_params struct. Get rid o' p");
8970  return NULL;
8971  }
8972 
8973  if (logger_callid) {
8975  }
8976 
8982 
8983  if (!p->caps|| !p->jointcaps || !p->peercaps || !p->redircaps || !p->prefcaps) {
8984  ao2_cleanup(p->caps);
8985  ao2_cleanup(p->jointcaps);
8986  ao2_cleanup(p->peercaps);
8987  ao2_cleanup(p->redircaps);
8988  ao2_cleanup(p->prefcaps);
8989  ao2_t_ref(p, -1, "Yuck, couldn't allocate format capabilities. Get rid o' p");
8990  return NULL;
8991  }
8992 
8993 
8994  /* If this dialog is created as a result of a request or response, lets store
8995  * some information about it in the dialog. */
8996  if (req) {
8997  struct sip_via *via;
8998  const char *cseq = sip_get_header(req, "Cseq");
8999  uint32_t seqno;
9000 
9001  /* get branch parameter from initial Request that started this dialog */
9002  via = parse_via(sip_get_header(req, "Via"));
9003  if (via) {
9004  /* only store the branch if it begins with the magic prefix "z9hG4bK", otherwise
9005  * it is not useful to us to have it */
9006  if (!ast_strlen_zero(via->branch) && !strncasecmp(via->branch, "z9hG4bK", 7)) {
9007  ast_string_field_set(p, initviabranch, via->branch);
9008  ast_string_field_set(p, initviasentby, via->sent_by);
9009  }
9010  free_via(via);
9011  }
9012 
9013  /* Store initial incoming cseq. An error in sscanf here is ignored. There is no approperiate
9014  * except not storing the number. CSeq validation must take place before dialog creation in find_call */
9015  if (!ast_strlen_zero(cseq) && (sscanf(cseq, "%30u", &seqno) == 1)) {
9016  p->init_icseq = seqno;
9017  }
9018  /* Later in ast_sip_ouraddrfor we need this to choose the right ip and port for the specific transport */
9020  } else {
9022  }
9023 
9024  p->socket.fd = -1;
9025  p->method = intended_method;
9026  p->initid = -1;
9027  p->waitid = -1;
9028  p->reinviteid = -1;
9029  p->autokillid = -1;
9030  p->request_queue_sched_id = -1;
9032  p->t38id = -1;
9033  p->subscribed = NONE;
9034  p->stateid = -1;
9035  p->sessionversion_remote = -1;
9036  p->session_modify = TRUE;
9037  p->stimer = NULL;
9038  ast_copy_string(p->zone, default_zone, sizeof(p->zone));
9040 
9041  if (intended_method != SIP_OPTIONS) { /* Peerpoke has it's own system */
9042  p->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */
9043  p->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */
9044  }
9045 
9046  if (!addr) {
9047  p->ourip = internip;
9048  } else {
9049  ast_sockaddr_copy(&p->sa, addr);
9050  ast_sip_ouraddrfor(&p->sa, &p->ourip, p);
9051  }
9052 
9053  /* Copy global flags to this PVT at setup. */
9057 
9059 
9060  p->branch = ast_random();
9061  make_our_tag(p);
9062  p->ocseq = INITIAL_CSEQ;
9063  p->allowed_methods = UINT_MAX;
9064 
9065  if (sip_methods[intended_method].need_rtp) {
9068  }
9069 
9070  if (useglobal_nat && addr) {
9071  /* Setup NAT structure according to global settings if we have an address */
9072  ast_sockaddr_copy(&p->recv, addr);
9073  check_via(p, req);
9074  do_setnat(p);
9075  }
9076 
9077  if (p->method != SIP_REGISTER) {
9078  ast_string_field_set(p, fromdomain, default_fromdomain);
9080  }
9081  build_via(p);
9082  if (!callid)
9083  build_callid_pvt(p);
9084  else
9085  ast_string_field_set(p, callid, callid);
9086  /* Assign default music on hold class */
9091  if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
9092  (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) {
9094  }
9098 
9101 
9102  /* Add to active dialog list */
9103 
9104  ao2_t_link(dialogs, p, "link pvt into dialogs table");
9105 
9106  ast_debug(1, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : p->callid, sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP");
9107  return p;
9108 }
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:365
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define ao2_t_link(container, obj, tag)
Add an object to a container.
Definition: astobj2.h:1547
void * __ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
Definition: astobj2.c:768
#define ast_cc_config_params_init()
Allocate and initialize an ast_cc_config_params structure.
Definition: ccss.h:135
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:120
static char mohinterpret[MAX_MUSICCLASS]
Definition: chan_alsa.c:123
static char mohsuggest[MAX_MUSICCLASS]
Definition: chan_iax2.c:427
static char parkinglot[AST_MAX_CONTEXT]
Definition: chan_mgcp.c:166
static void sip_pvt_callid_set(struct sip_pvt *pvt, ast_callid callid)
Definition: chan_sip.c:8941
static void make_our_tag(struct sip_pvt *pvt)
Make our SIP dialog tag.
Definition: chan_sip.c:8916
static void ast_sip_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us, struct sip_pvt *p)
NAT fix - decide which IP address to use for Asterisk server?
Definition: chan_sip.c:3873
static char default_mohsuggest[MAX_MUSICCLASS]
Definition: chan_sip.c:804
static unsigned int global_autoframing
Definition: chan_sip.c:854
static char default_engine[256]
Definition: chan_sip.c:807
static unsigned int recordhistory
Definition: chan_sip.c:845
static char default_parkinglot[AST_MAX_CONTEXT]
Definition: chan_sip.c:806
static int global_t1
Definition: chan_sip.c:851
static char default_zone[MAX_TONEZONE_COUNTRY]
Definition: chan_sip.c:809
static void sip_pvt_dtor(void *vdoomed)
ao2 destructor for SIP dialog structure
Definition: chan_sip.c:6683
static int default_fromdomainport
Definition: chan_sip.c:798
static void check_via(struct sip_pvt *p, const struct sip_request *req)
check Via: header for hostname, port and rport request/answer
Definition: chan_sip.c:19171
static char default_mohinterpret[MAX_MUSICCLASS]
Definition: chan_sip.c:803
static int global_timer_b
Definition: chan_sip.c:853
static struct ast_sockaddr internip
our (internal) default address/port to put in SIP/SDP messages internip is initialized picking a suit...
Definition: chan_sip.c:1118
static void set_socket_transport(struct sip_socket *socket, int transport)
Definition: chan_sip.c:16636
static int default_maxcallbitrate
Definition: chan_sip.c:808
static void build_via(struct sip_pvt *p)
Build a Via header for a request.
Definition: chan_sip.c:3854
static void do_setnat(struct sip_pvt *p)
Set nat mode on the various data sockets.
Definition: chan_sip.c:5870
static struct ast_flags global_flags[3]
Definition: chan_sip.c:888
static char default_fromdomain[AST_MAX_EXTENSION]
Definition: chan_sip.c:797
static void build_callid_pvt(struct sip_pvt *pvt)
Build SIP Call-ID value for a non-REGISTER transaction.
Definition: chan_sip.c:8839
@ AST_MEDIA_TYPE_UNKNOWN
Definition: codec.h:31
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition: format_cap.h:38
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:171
@ AST_TRANSPORT_UDP
Definition: netsock2.h:60
#define AST_RTP_DTMF
Definition: rtp_engine.h:266
#define SIP_DTMF_RFC2833
Definition: sip.h:269
#define SIP_PAGE3_FLAGS_TO_COPY
Definition: sip.h:389
#define SIP_DTMF
Definition: sip.h:268
@ NONE
Definition: sip.h:467
#define SIP_DTMF_AUTO
Definition: sip.h:272
#define SIP_PAGE2_FLAGS_TO_COPY
Definition: sip.h:368
#define SIP_FLAGS_TO_COPY
Flags to copy from peer/user to dialog.
Definition: sip.h:306
@ SIP_OPTIONS
Definition: sip.h:609
#define INITIAL_CSEQ
Definition: sip.h:110
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
unsigned int allowed_methods
Definition: sip.h:1189
unsigned short session_modify
Definition: sip.h:1080
char zone[MAX_TONEZONE_COUNTRY]
Definition: sip.h:1109
unsigned short do_history
Definition: sip.h:1071
int maxforwards
Definition: sip.h:1058
struct ast_format_cap * peercaps
Definition: sip.h:1094
uint32_t init_icseq
Definition: sip.h:1062
struct ast_flags flags[3]
Definition: sip.h:1068
int fromdomainport
Definition: sip.h:1213
enum transfermodes allowtransfer
Definition: sip.h:1130
int noncodeccapability
Definition: sip.h:1097
struct ast_format_cap * redircaps
Definition: sip.h:1095
int provisional_keepalive_sched_id
Definition: sip.h:1102
int timer_b
Definition: sip.h:1089
int64_t sessionversion_remote
Definition: sip.h:1116
int reinviteid
Definition: sip.h:1150
struct ast_format_cap * prefcaps
Definition: sip.h:1096
struct ast_sockaddr recv
Definition: sip.h:1128
int waitid
Definition: sip.h:1149
struct ast_format_cap * caps
Definition: sip.h:1092
int stateid
Definition: sip.h:1155
struct sip_pvt::@162 offered_media
uint32_t ocseq
Definition: sip.h:1060
struct ast_rtp_instance * rtp
Definition: sip.h:1167
struct ast_format_cap * jointcaps
Definition: sip.h:1093
int request_queue_sched_id
Definition: sip.h:1101
unsigned short autoframing
Definition: sip.h:1082
int maxcallbitrate
Definition: sip.h:1099
struct ast_sockaddr sa
Definition: sip.h:1118
long branch
Definition: sip.h:1114
int t38id
Definition: sip.h:1152
enum subscriptiontype subscribed
Definition: sip.h:1154
struct sip_socket socket
Definition: sip.h:1059
struct ast_cc_config_params * cc_params
Definition: sip.h:1211
int timer_t1
Definition: sip.h:1088
struct ast_sockaddr ourip
Definition: sip.h:1129
int autokillid
Definition: sip.h:1151
struct sip_st_dlg * stimer
Definition: sip.h:1177
struct sip_pvt::request_queue request_queue
int initid
Definition: sip.h:1148
struct sip_socket socket
Definition: sip.h:839
enum transfermodes allowtransfer
Definition: sip.h:769
struct ast_format_cap * caps
Global list of addresses dynamic peers are not allowed to use.
Definition: sip.h:780
char default_context[AST_MAX_CONTEXT]
Definition: sip.h:775
int default_max_forwards
Definition: sip.h:782
enum ast_transport type
Definition: sip.h:791
int fd
Definition: sip.h:792
#define ast_test_flag(p, flag)
Definition: utils.h:63
long int ast_random(void)
Definition: main/utils.c:2064
#define ast_copy_flags(dest, src, flagz)
Definition: utils.h:84

References __ao2_alloc(), sip_pvt::allowed_methods, sip_settings::allowtransfer, sip_pvt::allowtransfer, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_cleanup, ao2_t_link, ao2_t_ref, ast_cc_config_params_init, ast_copy_flags, ast_copy_string(), ast_debug, ast_format_cap_alloc, ast_format_cap_append_from_cap(), AST_FORMAT_CAP_FLAG_DEFAULT, AST_LIST_HEAD_INIT_NOLOCK, AST_MEDIA_TYPE_UNKNOWN, ast_random(), AST_RTP_DTMF, ast_sip_ouraddrfor(), ast_sockaddr_copy(), ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_test_flag, AST_TRANSPORT_UDP, sip_pvt::autoframing, sip_pvt::autokillid, sip_via::branch, sip_pvt::branch, build_callid_pvt(), build_via(), sip_pvt::callid, sip_settings::caps, sip_pvt::caps, sip_pvt::cc_params, check_via(), context, sip_settings::default_context, default_engine, default_fromdomain, default_fromdomainport, sip_settings::default_max_forwards, default_maxcallbitrate, default_mohinterpret, default_mohsuggest, default_parkinglot, default_zone, dialogs, sip_pvt::do_history, do_setnat(), sip_socket::fd, make_ari_stubs::file, sip_pvt::flags, free_via(), sip_pvt::fromdomainport, global_autoframing, global_flags, global_t1, global_timer_b, sip_pvt::init_icseq, INITIAL_CSEQ, sip_pvt::initid, internip, sip_pvt::jointcaps, make_our_tag(), sip_pvt::maxcallbitrate, sip_pvt::maxforwards, sip_pvt::method, mohinterpret, mohsuggest, sip_pvt::noncodeccapability, NONE, NULL, sip_pvt::ocseq, sip_pvt::offered_media, sip_pvt::ourip, parkinglot, parse_via(), sip_pvt::peercaps, sip_pvt::prefcaps, sip_pvt::provisional_keepalive_sched_id, recordhistory, sip_pvt::recv, sip_pvt::redircaps, sip_pvt::reinviteid, sip_pvt::request_queue, sip_pvt::request_queue_sched_id, sip_pvt::rtp, sip_pvt::sa, sip_via::sent_by, sip_pvt::session_modify, sip_pvt::sessionversion_remote, set_socket_transport(), sip_cfg, SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_RFC2833, SIP_FLAGS_TO_COPY, sip_get_header(), sip_methods, SIP_OPTIONS, SIP_PAGE2_FLAGS_TO_COPY, SIP_PAGE3_FLAGS_TO_COPY, sip_pvt_callid_set(), sip_pvt_dtor(), SIP_REGISTER, sip_request::socket, sip_pvt::socket, sip_pvt::stateid, sip_pvt::stimer, sip_pvt::subscribed, sip_pvt::t38id, cfsip_methods::text, sip_pvt::timer_b, sip_pvt::timer_t1, TRUE, sip_socket::type, sip_pvt::waitid, and sip_pvt::zone.

◆ __sip_autodestruct()

static int __sip_autodestruct ( const void *  data)
static

Kill a SIP dialog (called only by the scheduler) The scheduler has a reference to this dialog when p->autokillid != -1, and we are called using that reference. So if the event is not rescheduled, we need to call dialog_unref().

Definition at line 4377 of file chan_sip.c.

4378 {
4379  struct sip_pvt *p = (struct sip_pvt *)data;
4380  struct ast_channel *owner;
4381 
4382  /* If this is a subscription, tell the phone that we got a timeout */
4384  struct state_notify_data data = { 0, };
4385 
4387 
4388  transmit_state_notify(p, &data, 1, TRUE); /* Send last notification */
4389  p->subscribed = NONE;
4390  append_history(p, "Subscribestatus", "timeout");
4391  ast_debug(3, "Re-scheduled destruction of SIP subscription %s\n", p->callid ? p->callid : "<unknown>");
4392  return 10000; /* Reschedule this destruction so that we know that it's gone */
4393  }
4394 
4395  /* If there are packets still waiting for delivery, delay the destruction */
4396  if (p->packets) {
4397  if (!p->needdestroy) {
4398  char method_str[31];
4399 
4400  ast_debug(3, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>");
4401  append_history(p, "ReliableXmit", "timeout");
4402  if (sscanf(p->lastmsg, "Tx: %30s", method_str) == 1 || sscanf(p->lastmsg, "Rx: %30s", method_str) == 1) {
4403  if (p->ongoing_reinvite || method_match(SIP_CANCEL, method_str) || method_match(SIP_BYE, method_str)) {
4404  pvt_set_needdestroy(p, "autodestruct");
4405  }
4406  }
4407  return 10000;
4408  } else {
4409  /* They've had their chance to respond. Time to bail */
4410  __sip_pretend_ack(p);
4411  }
4412  }
4413 
4414  /*
4415  * Lock both the pvt and the channel safely so that we can queue up a frame.
4416  */
4417  owner = sip_pvt_lock_full(p);
4418  if (owner) {
4420  "Autodestruct on dialog '%s' with owner %s in place (Method: %s). Rescheduling destruction for 10000 ms\n",
4421  p->callid, ast_channel_name(owner), sip_methods[p->method].text);
4423  ast_channel_unlock(owner);
4424  ast_channel_unref(owner);
4425  sip_pvt_unlock(p);
4426  return 10000;
4427  }
4428 
4429  /* Reset schedule ID */
4430  p->autokillid = -1;
4431 
4432  if (p->refer && !p->alreadygone) {
4433  ast_debug(3, "Finally hanging up channel after transfer: %s\n", p->callid);
4434  stop_media_flows(p);
4436  append_history(p, "ReferBYE", "Sending BYE on transferer call leg %s", p->callid);
4438  sip_pvt_unlock(p);
4439  } else {
4440  append_history(p, "AutoDestroy", "%s", p->callid);
4441  ast_debug(3, "Auto destroying SIP dialog '%s'\n", p->callid);
4442  sip_pvt_unlock(p);
4443  dialog_unlink_all(p); /* once it's unlinked and unrefd everywhere, it'll be freed automagically */
4444  }
4445 
4446  dialog_unref(p, "autokillid complete");
4447 
4448  return 0;
4449 }
#define AST_CAUSE_PROTOCOL_ERROR
Definition: causes.h:144
static int transmit_state_notify(struct sip_pvt *p, struct state_notify_data *data, int full, int timeout)
Used in the SUBSCRIBE notification subsystem (RFC3265)
Definition: chan_sip.c:15484
#define append_history(p, event, fmt, args...)
Append to SIP dialog history.
Definition: chan_sip.c:2410
static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, uint32_t seqno, enum xmittype reliable, int newbranch)
Transmit SIP request, auth added.
Definition: chan_sip.c:16571
void sip_scheddestroy(struct sip_pvt *p, int ms)
Schedule destruction of SIP dialog.
Definition: chan_sip.c:4557
static void pvt_set_needdestroy(struct sip_pvt *pvt, const char *reason)
Definition: chan_sip.c:3436
static void stop_media_flows(struct sip_pvt *p)
Immediately stop RTP, VRTP and UDPTL as applicable.
Definition: chan_sip.c:25163
void __sip_pretend_ack(struct sip_pvt *p)
Pretend to ack all packets called with p locked.
Definition: chan_sip.c:4623
static int method_match(enum sipmethod id, const char *name)
returns true if 'name' (with optional trailing whitespace) matches the sip method 'id'....
Definition: chan_sip.c:3591
const char * ast_channel_name(const struct ast_channel *chan)
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1156
@ AST_EXTENSION_DEACTIVATED
Definition: pbx.h:63
#define DEFAULT_TRANS_TIMEOUT
Definition: sip.h:100
@ CALL_COMPLETION
Definition: sip.h:473
@ MWI_NOTIFICATION
Definition: sip.h:472
@ XMIT_RELIABLE
Definition: sip.h:453
@ SIP_CANCEL
Definition: sip.h:620
char lastmsg[256]
Definition: sip.h:1138
unsigned short alreadygone
Definition: sip.h:1072
struct sip_refer * refer
Definition: sip.h:1153
unsigned short needdestroy
Definition: sip.h:1073
unsigned int ongoing_reinvite
Definition: sip.h:1137

References __sip_pretend_ack(), sip_pvt::alreadygone, append_history, AST_CAUSE_PROTOCOL_ERROR, ast_channel_name(), ast_channel_unlock, ast_channel_unref, ast_debug, AST_EXTENSION_DEACTIVATED, ast_log, ast_queue_hangup_with_cause(), sip_pvt::autokillid, CALL_COMPLETION, sip_pvt::callid, DEFAULT_TRANS_TIMEOUT, dialog_unlink_all(), dialog_unref, sip_pvt::lastmsg, LOG_WARNING, sip_pvt::method, method_match(), MWI_NOTIFICATION, sip_pvt::needdestroy, NONE, sip_pvt::ongoing_reinvite, sip_pvt::packets, pvt_set_needdestroy(), sip_pvt::refer, SIP_BYE, SIP_CANCEL, sip_methods, sip_pvt_lock_full(), sip_pvt_unlock, sip_scheddestroy(), state_notify_data::state, stop_media_flows(), sip_pvt::subscribed, cfsip_methods::text, transmit_request_with_auth(), transmit_state_notify(), TRUE, and XMIT_RELIABLE.

Referenced by __sip_scheddestroy(), and sip_show_sched().

◆ __sip_cancel_destroy()

static int __sip_cancel_destroy ( const void *  data)
static

Definition at line 4461 of file chan_sip.c.

4462 {
4463  struct sip_pvt *pvt = (void *) data;
4464 
4465  sip_pvt_lock(pvt);
4466  do_cancel_destroy(pvt);
4467  sip_pvt_unlock(pvt);
4468  dialog_unref(pvt, "Cancel destroy action");
4469  return 0;
4470 }
static void do_cancel_destroy(struct sip_pvt *pvt)
Definition: chan_sip.c:4451

References dialog_unref, do_cancel_destroy(), sip_pvt_lock, and sip_pvt_unlock.

Referenced by sip_cancel_destroy().

◆ __sip_do_register()

static int __sip_do_register ( struct sip_registry r)
static

Register with SIP proxy.

Returns
see __sip_xmit

Definition at line 15916 of file chan_sip.c.

15917 {
15918  int res;
15919 
15921  return res;
15922 }
static int transmit_register(struct sip_registry *r, int sipmethod, const char *auth, const char *authheader)
Transmit register to SIP proxy or UA auth = NULL on the initial registration (from sip_reregister())
Definition: chan_sip.c:16113

References NULL, SIP_REGISTER, and transmit_register().

Referenced by sip_reregister().

◆ __sip_pretend_ack()

void __sip_pretend_ack ( struct sip_pvt p)

Pretend to ack all packets called with p locked.

Definition at line 4623 of file chan_sip.c.

4624 {
4625  struct sip_pkt *cur = NULL;
4626 
4627  while (p->packets) {
4628  int method;
4629  if (cur == p->packets) {
4630  ast_log(LOG_WARNING, "Have a packet that doesn't want to give up! %s\n", sip_methods[cur->method].text);
4631  return;
4632  }
4633  cur = p->packets;
4634  method = (cur->method) ? cur->method : find_sip_method(ast_str_buffer(cur->data));
4635  __sip_ack(p, cur->seqno, cur->is_resp, method);
4636  }
4637 }
static int find_sip_method(const char *msg)
find_sip_method: Find SIP method from header
Definition: chan_sip.c:3601
int __sip_ack(struct sip_pvt *p, uint32_t seqno, int resp, int sipmethod)
Acknowledges receipt of a packet and stops retransmission called with p locked.
Definition: chan_sip.c:4578
const char * method
Definition: res_pjsip.c:4372
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:727
struct ast_str * data
Definition: sip.h:1239

References __sip_ack(), ast_log, ast_str_buffer(), sip_pkt::data, find_sip_method(), sip_pkt::is_resp, LOG_WARNING, sip_pkt::method, method, NULL, sip_pvt::packets, sip_pkt::seqno, sip_methods, and cfsip_methods::text.

Referenced by __sip_autodestruct(), handle_request_bye(), handle_request_cancel(), and sip_reg_timeout().

◆ __sip_reliable_xmit()

static enum sip_result __sip_reliable_xmit ( struct sip_pvt p,
uint32_t  seqno,
int  resp,
struct ast_str data,
int  fatal,
int  sipmethod 
)
static

Definition at line 4267 of file chan_sip.c.

4284 {
4285  struct sip_pkt *pkt = NULL;
4286  int siptimer_a = DEFAULT_RETRANS;
4287  int xmitres = 0;
4288  unsigned respid;
4289 
4290  if (sipmethod == SIP_INVITE) {
4291  /* Note this is a pending invite */
4292  p->pendinginvite = seqno;
4293  }
4294 
4296  if (!pkt) {
4297  return AST_FAILURE;
4298  }
4299  /* copy data, add a terminator and save length */
4301  if (!pkt->data) {
4302  ao2_t_ref(pkt, -1, "Failed to initialize");
4303  return AST_FAILURE;
4304  }
4305  ast_str_set(&pkt->data, 0, "%s%s", ast_str_buffer(data), "\0");
4306  /* copy other parameters from the caller */
4307  pkt->method = sipmethod;
4308  pkt->seqno = seqno;
4309  pkt->is_resp = resp;
4310  pkt->is_fatal = fatal;
4311  pkt->owner = dialog_ref(p, "__sip_reliable_xmit: setting pkt->owner");
4312 
4313  /* The retransmission list owns a pkt ref */
4314  pkt->next = p->packets;
4315  p->packets = pkt; /* Add it to the queue */
4316 
4317  if (resp) {
4318  /* Parse out the response code */
4319  if (sscanf(ast_str_buffer(pkt->data), "SIP/2.0 %30u", &respid) == 1) {
4320  pkt->response_code = respid;
4321  }
4322  }
4323  pkt->timer_t1 = p->timer_t1; /* Set SIP timer T1 */
4324  if (pkt->timer_t1) {
4325  siptimer_a = pkt->timer_t1;
4326  }
4327 
4328  pkt->time_sent = ast_tvnow(); /* time packet was sent */
4329  pkt->retrans_stop_time = 64 * (pkt->timer_t1 ? pkt->timer_t1 : DEFAULT_TIMER_T1); /* time in ms after pkt->time_sent to stop retransmission */
4330 
4331  if (!(p->socket.type & AST_TRANSPORT_UDP)) {
4332  /* TCP does not need retransmits as that's built in, but with
4333  * retrans_stop set, we must give it the full timer_H treatment */
4334  pkt->retrans_stop = 1;
4335  siptimer_a = pkt->retrans_stop_time;
4336  }
4337 
4338  /* Schedule retransmission */
4339  ao2_t_ref(pkt, +1, "Schedule packet retransmission");
4340  pkt->retransid = ast_sched_add_variable(sched, siptimer_a, retrans_pkt, pkt, 1);
4341  if (pkt->retransid < 0) {
4342  ao2_t_ref(pkt, -1, "Failed to schedule packet retransmission");
4343  }
4344 
4345  if (sipdebug) {
4346  ast_debug(4, "*** SIP TIMER: Initializing retransmit timer on packet: Id #%d\n", pkt->retransid);
4347  }
4348 
4349  xmitres = __sip_xmit(pkt->owner, pkt->data); /* Send packet */
4350 
4351  if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */
4352  append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)");
4353  ast_log(LOG_ERROR, "Serious Network Trouble; __sip_xmit returns error for pkt data\n");
4354 
4355  /* Unlink and destroy the packet object. */
4356  p->packets = pkt->next;
4357  stop_retrans_pkt(pkt);
4358  ao2_t_ref(pkt, -1, "Packet retransmission list");
4359  return AST_FAILURE;
4360  } else {
4361  /* This is odd, but since the retrans timer starts at 500ms and the do_monitor thread
4362  * only wakes up every 1000ms by default, we have to poke the thread here to make
4363  * sure it successfully detects this must be retransmitted in less time than
4364  * it usually sleeps for. Otherwise it might not retransmit this packet for 1000ms. */
4366  pthread_kill(monitor_thread, SIGURG);
4367  }
4368  return AST_SUCCESS;
4369  }
4370 }
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:369
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define DEFAULT_RETRANS
Definition: chan_mgcp.c:129
static void sip_pkt_dtor(void *vdoomed)
Definition: chan_sip.c:4267
static int __sip_xmit(struct sip_pvt *p, struct ast_str *data)
Definition: chan_sip.c:3808
static int retrans_pkt(const void *data)
Retransmit SIP message if no answer.
Definition: chan_sip.c:4048
static pthread_t monitor_thread
This is the thread for the monitor which checks for input on the channels which are not currently in ...
Definition: chan_sip.c:907
#define AST_PTHREADT_NULL
Definition: lock.h:66
#define LOG_ERROR
Definition: logger.h:286
int ast_sched_add_variable(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
Adds a scheduled event with rescheduling support.
Definition: sched.c:524
#define DEFAULT_TIMER_T1
Definition: sip.h:96
#define XMIT_ERROR
Definition: sip.h:58
@ AST_SUCCESS
Definition: sip.h:414
@ AST_FAILURE
Definition: sip.h:415
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:633
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1078
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:701
int64_t retrans_stop_time
Definition: sip.h:1237
int retrans_stop
Definition: sip.h:1238
struct timeval time_sent
Definition: sip.h:1236
char is_fatal
Definition: sip.h:1230
struct sip_pvt * owner
Definition: sip.h:1232
int response_code
Definition: sip.h:1231
int timer_t1
Definition: sip.h:1235
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150

References ast_free, sip_pkt::data, dialog_unref, and sip_pkt::owner.

Referenced by send_request(), and send_response().

◆ __sip_scheddestroy()

static int __sip_scheddestroy ( const void *  data)
static

Definition at line 4492 of file chan_sip.c.

4493 {
4494  struct sip_scheddestroy_data *sched_data = (void *) data;
4495  struct sip_pvt *pvt = sched_data->pvt;
4496  int ms = sched_data->ms;
4497 
4498  ast_free(sched_data);
4499 
4500  sip_pvt_lock(pvt);
4501  do_cancel_destroy(pvt);
4502 
4503  if (pvt->do_history) {
4504  append_history(pvt, "SchedDestroy", "%d ms", ms);
4505  }
4506 
4507  dialog_ref(pvt, "Schedule autokillid");
4509  if (pvt->autokillid < 0) {
4510  /* Uh Oh. Expect bad behavior. */
4511  dialog_unref(pvt, "Failed to schedule autokillid");
4512  }
4513 
4514  if (pvt->stimer) {
4515  stop_session_timer(pvt);
4516  }
4517  sip_pvt_unlock(pvt);
4518  dialog_unref(pvt, "Destroy action");
4519  return 0;
4520 }
#define ast_free(a)
Definition: astmm.h:182
static int __sip_autodestruct(const void *data)
Kill a SIP dialog (called only by the scheduler) The scheduler has a reference to this dialog when p-...
Definition: chan_sip.c:4377
static void stop_session_timer(struct sip_pvt *p)
Session-Timers: Stop session timer.
Definition: chan_sip.c:30223
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
Definition: sched.c:565
struct sip_pvt * pvt
Definition: chan_sip.c:4487

References __sip_autodestruct(), append_history, ast_free, ast_sched_add(), sip_pvt::autokillid, dialog_ref, dialog_unref, do_cancel_destroy(), sip_pvt::do_history, sip_scheddestroy_data::ms, sip_scheddestroy_data::pvt, sip_pvt_lock, sip_pvt_unlock, sip_pvt::stimer, and stop_session_timer().

Referenced by sip_scheddestroy_full().

◆ __sip_semi_ack()

int __sip_semi_ack ( struct sip_pvt p,
uint32_t  seqno,
int  resp,
int  sipmethod 
)

Acks receipt of packet, keep it around (used for provisional responses)

Definition at line 4640 of file chan_sip.c.

4641 {
4642  struct sip_pkt *cur;
4643  int res = FALSE;
4644 
4645  for (cur = p->packets; cur; cur = cur->next) {
4646  if (cur->seqno == seqno && cur->is_resp == resp &&
4647  (cur->is_resp || method_match(sipmethod, ast_str_buffer(cur->data)))) {
4648  /* this is our baby */
4649  if (cur->retransid > -1) {
4650  if (sipdebug)
4651  ast_debug(4, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text);
4652  }
4653  stop_retrans_pkt(cur);
4654  res = TRUE;
4655  break;
4656  }
4657  }
4658  ast_debug(1, "(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %u: %s\n", p->callid, resp ? "Response" : "Request", seqno, res == -1 ? "Not Found" : "Found");
4659  return res;
4660 }

References ast_debug, ast_str_buffer(), sip_pvt::callid, sip_pkt::data, FALSE, sip_pkt::is_resp, method_match(), sip_pkt::next, sip_pvt::packets, sip_pkt::retransid, sip_pkt::seqno, sip_methods, sipdebug, stop_retrans_pkt(), cfsip_methods::text, and TRUE.

Referenced by handle_response(), and sip_hangup().

◆ __sip_subscribe_mwi_do()

static int __sip_subscribe_mwi_do ( struct sip_subscription_mwi mwi)
static

Actually setup an MWI subscription or resubscribe.

Definition at line 15082 of file chan_sip.c.

15083 {
15084  /* If we have no DNS manager let's do a lookup */
15085  if (!mwi->dnsmgr) {
15086  char transport[MAXHOSTNAMELEN];
15087  snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(mwi->transport), get_srv_protocol(mwi->transport));
15088 
15089  mwi->us.ss.ss_family = get_address_family_filter(mwi->transport); /* Filter address family */
15090  ao2_t_ref(mwi, +1, "dnsmgr reference to mwi");
15091  ast_dnsmgr_lookup_cb(mwi->hostname, &mwi->us, &mwi->dnsmgr, sip_cfg.srvlookup ? transport : NULL, on_dns_update_mwi, mwi);
15092  if (!mwi->dnsmgr) {
15093  ao2_t_ref(mwi, -1, "dnsmgr disabled, remove reference");
15094  }
15095  }
15096 
15097  /* If we already have a subscription up simply send a resubscription */
15098  if (mwi->call) {
15099  transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 0, NULL);
15100  return 0;
15101  }
15102 
15103  /* Create a dialog that we will use for the subscription */
15104  if (!(mwi->call = sip_alloc(NULL, NULL, 0, SIP_SUBSCRIBE, NULL, 0))) {
15105  return -1;
15106  }
15107 
15108  ref_proxy(mwi->call, obproxy_get(mwi->call, NULL));
15109 
15110  if (!ast_sockaddr_port(&mwi->us) && mwi->portno) {
15111  ast_sockaddr_set_port(&mwi->us, mwi->portno);
15112  }
15113 
15114  /* Setup the destination of our subscription */
15115  if (create_addr(mwi->call, mwi->hostname, &mwi->us, 0)) {
15116  dialog_unlink_all(mwi->call);
15117  mwi->call = dialog_unref(mwi->call, "unref dialog after unlink_all");
15118  return 0;
15119  }
15120 
15121  mwi->call->expiry = mwi_expiry;
15122 
15123  if (!mwi->dnsmgr && mwi->portno) {
15124  ast_sockaddr_set_port(&mwi->call->sa, mwi->portno);
15125  ast_sockaddr_set_port(&mwi->call->recv, mwi->portno);
15126  } else {
15127  mwi->portno = ast_sockaddr_port(&mwi->call->sa);
15128  }
15129 
15130  /* Set various other information */
15131  if (!ast_strlen_zero(mwi->authuser)) {
15132  ast_string_field_set(mwi->call, peername, mwi->authuser);
15133  ast_string_field_set(mwi->call, authname, mwi->authuser);
15134  ast_string_field_set(mwi->call, fromuser, mwi->authuser);
15135  } else {
15136  ast_string_field_set(mwi->call, peername, mwi->username);
15137  ast_string_field_set(mwi->call, authname, mwi->username);
15138  ast_string_field_set(mwi->call, fromuser, mwi->username);
15139  }
15140  ast_string_field_set(mwi->call, username, mwi->username);
15141  if (!ast_strlen_zero(mwi->secret)) {
15142  ast_string_field_set(mwi->call, peersecret, mwi->secret);
15143  }
15144  set_socket_transport(&mwi->call->socket, mwi->transport);
15145  ast_sip_ouraddrfor(&mwi->call->sa, &mwi->call->ourip, mwi->call);
15146  build_via(mwi->call);
15147 
15148  /* Change the dialog callid. */
15149  change_callid_pvt(mwi->call, NULL);
15150 
15151  ast_set_flag(&mwi->call->flags[0], SIP_OUTGOING);
15152 
15153  /* Associate the call with us */
15154  mwi->call->mwi = ao2_t_bump(mwi, "Reference mwi from it's call");
15155 
15157 
15158  /* Actually send the packet */
15159  transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 2, NULL);
15160 
15161  return 0;
15162 }
#define ao2_t_bump(obj, tag)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:483
static const char * get_srv_service(enum ast_transport t)
Return service string for srv dns query.
Definition: chan_sip.c:3768
static int create_addr(struct sip_pvt *dialog, const char *opeer, struct ast_sockaddr *addr, int newdialog)
create address structure from device name Or, if peer not found, find it in the global DNS returns TR...
Definition: chan_sip.c:6327
static const char * get_srv_protocol(enum ast_transport t)
Return protocol string for srv dns query.
Definition: chan_sip.c:3750
static int get_address_family_filter(unsigned int transport)
Helper for dns resolution to filter by address family.
Definition: chan_sip.c:29567
static void change_callid_pvt(struct sip_pvt *pvt, const char *callid)
Definition: chan_sip.c:8868
static void on_dns_update_mwi(struct ast_sockaddr *old, struct ast_sockaddr *new, void *data)
Definition: chan_sip.c:15065
static int mwi_expiry
Definition: chan_sip.c:676
static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init, const char *const explicit_uri)
Build REFER/INVITE/OPTIONS/SUBSCRIBE message and transmit it.
Definition: chan_sip.c:14762
static struct sip_proxy * obproxy_get(struct sip_pvt *dialog, struct sip_peer *peer)
Get default outbound proxy or global proxy.
Definition: chan_sip.c:3556
int ast_dnsmgr_lookup_cb(const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service, dns_update_func func, void *data)
Allocate and initialize a DNS manager entry, with update callback.
Definition: dnsmgr.c:196
#define MAXHOSTNAMELEN
Definition: network.h:69
#define SIP_OUTGOING
Definition: sip.h:250
@ SIP_SUBSCRIBE
Definition: sip.h:616
struct sockaddr_storage ss
Definition: netsock2.h:98
int expiry
Definition: sip.h:1111
struct sip_subscription_mwi * mwi
Definition: sip.h:1185
int srvlookup
Definition: sip.h:751
const ast_string_field authuser
Definition: sip.h:1454
enum ast_transport transport
Definition: sip.h:1455
const ast_string_field username
Definition: sip.h:1454
struct sip_pvt * call
Definition: sip.h:1459
struct ast_sockaddr us
Definition: sip.h:1461
const ast_string_field secret
Definition: sip.h:1454
const ast_string_field hostname
Definition: sip.h:1454
#define ast_set_flag(p, flag)
Definition: utils.h:70

References ao2_t_bump, ao2_t_ref, ast_dnsmgr_lookup_cb(), ast_set_flag, ast_sip_ouraddrfor(), ast_sockaddr_port, ast_sockaddr_set_port, ast_string_field_set, ast_strlen_zero(), sip_subscription_mwi::authuser, build_via(), sip_subscription_mwi::call, change_callid_pvt(), create_addr(), dialog_unlink_all(), dialog_unref, sip_subscription_mwi::dnsmgr,