[asterisk-commits] oej: branch oej/obproxyfailover r117261 - in /team/oej/obproxyfailover: ./ ch...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue May 20 06:25:18 CDT 2008
Author: oej
Date: Tue May 20 06:25:18 2008
New Revision: 117261
URL: http://svn.digium.com/view/asterisk?view=rev&rev=117261
Log:
Adding the obproxy patch from another branch
Modified:
team/oej/obproxyfailover/CREDITS
team/oej/obproxyfailover/channels/chan_sip.c
team/oej/obproxyfailover/configs/sip.conf.sample
Modified: team/oej/obproxyfailover/CREDITS
URL: http://svn.digium.com/view/asterisk/team/oej/obproxyfailover/CREDITS?view=diff&rev=117261&r1=117260&r2=117261
==============================================================================
--- team/oej/obproxyfailover/CREDITS (original)
+++ team/oej/obproxyfailover/CREDITS Tue May 20 06:25:18 2008
@@ -133,6 +133,8 @@
Voop A/S, Nuvio Inc, Inotel S.A and Foniris Telecom A/S - funding for rewrite of SIP transfers
+Talkplus, inc - outbound proxy support in chan_sip
+
Philippe Sultan - RADIUS CDR module
INRIA, http://www.inria.fr/
Modified: team/oej/obproxyfailover/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/obproxyfailover/channels/chan_sip.c?view=diff&rev=117261&r1=117260&r2=117261
==============================================================================
--- team/oej/obproxyfailover/channels/chan_sip.c (original)
+++ team/oej/obproxyfailover/channels/chan_sip.c Tue May 20 06:25:18 2008
@@ -365,6 +365,21 @@
REG_STATE_FAILED, /*!< Registration failed after several tries */
};
+/*! \brief definition of a sip proxy server
+ *
+ * For outbound proxies, this is allocated in the SIP peer dynamically or
+ * statically as the global_outboundproxy. The pointer in a SIP message is just
+ * a pointer and should *not* be de-allocated.
+ */
+struct sip_proxy {
+ char name[MAXHOSTNAMELEN]; /*!< DNS name of domain/host or IP */
+ struct sockaddr_in ip; /*!< Currently used IP address and port */
+ time_t last_dnsupdate; /*!< When this was resolved */
+ int force; /*!< If it's an outbound proxy, Force use of this outbound proxy for all outbound requests */
+ /* Room for a SRV record chain based on the name */
+};
+
+
#define CAN_NOT_CREATE_DIALOG 0
#define CAN_CREATE_DIALOG 1
#define CAN_CREATE_DIALOG_UNSUPPORTED_METHOD 2
@@ -568,6 +583,7 @@
static int global_t1min; /*!< T1 roundtrip time minimum */
static int global_autoframing; /*!< Turn autoframing on or off. */
static enum transfermodes global_allowtransfer; /*!< SIP Refer restriction scheme */
+static struct sip_proxy global_outboundproxy; /*!< Outbound proxy */
static int global_matchexterniplocally; /*!< Match externip/externhost setting against localnet setting */
@@ -964,6 +980,7 @@
int jointnoncodeccapability; /*!< Joint Non codec capability */
int redircodecs; /*!< Redirect codecs */
int maxcallbitrate; /*!< Maximum Call Bitrate for Video Calls */
+ struct sip_proxy *outboundproxy; /*!< Outbound proxy for this dialog */
struct t38properties t38; /*!< T38 settings */
struct sockaddr_in udptlredirip; /*!< Where our T.38 UDPTL should be going if not to us */
struct ast_udptl *udptl; /*!< T.38 UDPTL session */
@@ -1117,6 +1134,7 @@
int rtpkeepalive; /*!< Send RTP packets for keepalive */
ast_group_t callgroup; /*!< Call group */
ast_group_t pickupgroup; /*!< Pickup group */
+ struct sip_proxy *outboundproxy; /*!< Outbound proxy for this peer */
struct sockaddr_in addr; /*!< IP address of peer */
int maxcallbitrate; /*!< Maximum Bitrate for a video call */
@@ -1206,7 +1224,6 @@
static int externrefresh = 10;
static struct ast_ha *localaddr; /*!< List of local networks, on the same side of NAT as this Asterisk */
static struct in_addr __ourip;
-static struct sockaddr_in outboundproxyip;
static int ourport;
static struct sockaddr_in debugaddr;
@@ -1622,6 +1639,14 @@
set_udptl_peer: sip_set_udptl_peer,
};
+/*! \brief Append to SIP dialog history
+ \return Always returns 0 */
+#define append_history(p, event, fmt , args... ) append_history_full(p, "%-15s " fmt, event, ## args)
+
+static void append_history_full(struct sip_pvt *p, const char *fmt, ...)
+ __attribute__ ((format (printf, 2, 3)));
+
+
/*! \brief Convert transfer status to string */
static char *referstatus2str(enum referstatus rstatus)
{
@@ -1657,6 +1682,57 @@
ast_set_flag(&dialog->flags[0], SIP_ALREADYGONE);
}
+/*! Resolve DNS srv name or host name in a sip_proxy structure */
+static int proxy_update(struct sip_proxy *proxy)
+{
+ /* if it's actually an IP address and not a name,
+ there's no need for a managed lookup */
+ if (!inet_aton(proxy->name, &proxy->ip.sin_addr)) {
+ /* Ok, not an IP address, then let's check if it's a domain or host */
+ /* XXX Todo - if we have proxy port, don't do SRV */
+ if (ast_get_ip_or_srv(&proxy->ip, proxy->name, srvlookup ? "_sip._udp" : NULL) < 0) {
+ ast_log(LOG_WARNING, "Unable to locate host '%s'\n", proxy->name);
+ return FALSE;
+ }
+ }
+ proxy->last_dnsupdate = time(NULL);
+ return TRUE;
+}
+
+/*! \brief Allocate and initialize sip proxy */
+static struct sip_proxy *proxy_allocate(char *name, char *port, int force)
+{
+ struct sip_proxy *proxy;
+ proxy = ast_calloc(1, sizeof(struct sip_proxy));
+ if (!proxy)
+ return NULL;
+ proxy->force = force;
+ ast_copy_string(proxy->name, name, sizeof(proxy->name));
+ if (!ast_strlen_zero(port))
+ proxy->ip.sin_port = htons(atoi(port));
+ proxy_update(proxy);
+ return proxy;
+}
+
+/*! \brief Get default outbound proxy or global proxy */
+static struct sip_proxy *obproxy_get(struct sip_pvt *dialog, struct sip_peer *peer)
+{
+ if (peer && peer->outboundproxy) {
+ if (option_debug && sipdebug)
+ ast_log(LOG_DEBUG, "OBPROXY: Applying peer OBproxy to this call\n");
+ append_history(dialog, "OBproxy", "Using peer obproxy %s", peer->outboundproxy->name);
+ return peer->outboundproxy;
+ }
+ if (global_outboundproxy.name[0]) {
+ if (option_debug && sipdebug)
+ ast_log(LOG_DEBUG, "OBPROXY: Applying global OBproxy to this call\n");
+ append_history(dialog, "OBproxy", "Using global obproxy %s", global_outboundproxy.name);
+ return &global_outboundproxy;
+ }
+ if (option_debug && sipdebug)
+ ast_log(LOG_DEBUG, "OBPROXY: Not applying OBproxy to this call\n");
+ return NULL;
+}
/*! \brief returns true if 'name' (with optional trailing whitespace)
* matches the sip method 'id'.
@@ -1748,6 +1824,9 @@
/*! \brief The real destination address for a write */
static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p)
{
+ if (p->outboundproxy)
+ return &p->outboundproxy->ip;
+
return ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE ? &p->recv : &p->sa;
}
@@ -1835,13 +1914,6 @@
*us = bindaddr.sin_addr;
return AST_SUCCESS;
}
-
-/*! \brief Append to SIP dialog history
- \return Always returns 0 */
-#define append_history(p, event, fmt , args... ) append_history_full(p, "%-15s " fmt, event, ## args)
-
-static void append_history_full(struct sip_pvt *p, const char *fmt, ...)
- __attribute__ ((format (printf, 2, 3)));
/*! \brief Append to SIP dialog history with arg list */
static void append_history_va(struct sip_pvt *p, const char *fmt, va_list ap)
@@ -2149,6 +2221,13 @@
int res = FALSE;
msg = sip_methods[sipmethod].text;
+ /* If we have an outbound proxy for this dialog, then delete it now since
+ the rest of the requests in this dialog needs to follow the routing.
+ If obforcing is set, we will keep the outbound proxy during the whole
+ dialog, regardless of what the SIP rfc says
+ */
+ if (p->outboundproxy && !p->outboundproxy->force)
+ p->outboundproxy = NULL;
for (cur = p->packets; cur; prev = cur, cur = cur->next) {
if ((cur->seqno == seqno) && ((ast_test_flag(cur, FLAG_RESPONSE)) == resp) &&
@@ -2195,6 +2274,7 @@
ast_log(LOG_DEBUG, "Stopping retransmission on '%s' of %s %d: Match %s\n", p->callid, resp ? "Response" : "Request", seqno, res == FALSE ? "Not Found" : "Found");
}
+
/*! \brief Pretend to ack all packets
* called with p locked */
static void __sip_pretend_ack(struct sip_pvt *p)
@@ -2290,6 +2370,13 @@
{
int res;
+ /* If we have an outbound proxy, reset peer address
+ Only do this once.
+ */
+ if (p->outboundproxy) {
+ p->sa = p->outboundproxy->ip;
+ }
+
add_blank(req);
if (sip_debug_test_pvt(p)) {
if (ast_test_flag(&p->flags[0], SIP_NAT_ROUTE))
@@ -2462,6 +2549,9 @@
{
if (option_debug > 2)
ast_log(LOG_DEBUG, "Destroying SIP peer %s\n", peer->name);
+
+ if (peer->outboundproxy)
+ free(peer->outboundproxy);
/* Delete it, it needs to disappear */
if (peer->call)
@@ -2847,6 +2937,7 @@
ast_string_field_build(dialog, callid, "%s@%s", tmpcall, peer->fromdomain);
}
}
+ dialog->outboundproxy = obproxy_get(dialog, peer);
if (ast_strlen_zero(dialog->tohost))
ast_string_field_set(dialog, tohost, ast_inet_ntoa(dialog->sa.sin_addr));
if (!ast_strlen_zero(peer->fromdomain))
@@ -2904,6 +2995,18 @@
ASTOBJ_UNREF(p, sip_destroy_peer);
return res;
}
+ ast_string_field_set(dialog, tohost, peer);
+
+ /* Get the outbound proxy information */
+ dialog->outboundproxy = obproxy_get(dialog, NULL);
+
+ /* If we have an outbound proxy, don't bother with DNS resolution at all */
+ if (dialog->outboundproxy)
+ return 0;
+
+ /* Let's see if we can find the host in DNS. First try DNS SRV records,
+ then hostname lookup
+ */
hostn = peer;
portno = port ? atoi(port) : STANDARD_SIP_PORT;
if (srvlookup) {
@@ -2923,7 +3026,6 @@
ast_log(LOG_WARNING, "No such host: %s\n", peer);
return -1;
}
- ast_string_field_set(dialog, tohost, peer);
memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
dialog->sa.sin_port = htons(portno);
dialog->recv = dialog->sa;
@@ -7577,6 +7679,9 @@
}
if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
+
+ p->outboundproxy = obproxy_get(p, NULL);
+
/* Find address to hostname */
if (create_addr(p, r->hostname)) {
/* we have what we hope is a temporary network error,
@@ -7721,8 +7826,9 @@
add_header_contentLength(&req, 0);
initialize_initreq(p, &req);
- if (sip_debug_test_pvt(p))
+ if (sip_debug_test_pvt(p)) {
ast_verbose("REGISTER %d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
+ }
r->regstate = auth ? REG_STATE_AUTHSENT : REG_STATE_REGSENT;
r->regattempts++; /* Another attempt */
if (option_debug > 3)
@@ -10487,6 +10593,9 @@
ast_cli(fd, " Send RPID : %s\n", ast_test_flag(&peer->flags[0], SIP_SENDRPID) ? "Yes" : "No");
ast_cli(fd, " Subscriptions: %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE) ? "Yes" : "No");
ast_cli(fd, " Overlap dial : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWOVERLAP) ? "Yes" : "No");
+ if (peer->outboundproxy)
+ ast_cli(fd, " Outb. proxy : %s %s\n", ast_strlen_zero(peer->outboundproxy->name) ? "<not set>" : peer->outboundproxy->name,
+ peer->outboundproxy->force ? "(forced)" : "");
/* - is enumerated */
ast_cli(fd, " DTMFmode : %s\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF)));
@@ -10775,8 +10884,11 @@
ast_cli(fd, " Notify ringing state: %s\n", global_notifyringing ? "Yes" : "No");
ast_cli(fd, " Notify hold state: %s\n", global_notifyhold ? "Yes" : "No");
ast_cli(fd, " SIP Transfer mode: %s\n", transfermode2str(global_allowtransfer));
- ast_cli(fd, " Max Call Bitrate: %d kbps\r\n", default_maxcallbitrate);
- ast_cli(fd, " Auto-Framing: %s \r\n", global_autoframing ? "Yes" : "No");
+ ast_cli(fd, " Max Call Bitrate: %d kbps\n", default_maxcallbitrate);
+ ast_cli(fd, " Auto-Framing: %s\n", global_autoframing ? "Yes" : "No");
+ ast_cli(fd, " Outb. proxy: %s %s\n", ast_strlen_zero(global_outboundproxy.name) ? "<not set>" : global_outboundproxy.name,
+ global_outboundproxy.force ? "(forced)" : "");
+
ast_cli(fd, "\nDefault Settings:\n");
ast_cli(fd, "-----------------\n");
ast_cli(fd, " Context: %s\n", default_context);
@@ -16638,7 +16750,6 @@
{
struct sip_peer *peer = NULL;
struct ast_ha *oldha = NULL;
- int obproxyfound=0;
int found=0;
int firstpass=1;
int format=0; /* Ama flags */
@@ -16727,21 +16838,33 @@
ast_set2_flag(&peer->flags[0], ast_true(v->value), SIP_USEREQPHONE);
} else if (!strcasecmp(v->name, "fromuser")) {
ast_copy_string(peer->fromuser, v->value, sizeof(peer->fromuser));
- } else if (!strcasecmp(v->name, "host") || !strcasecmp(v->name, "outboundproxy")) {
+ } else if (!strcasecmp(v->name, "outboundproxy")) {
+ char *port, *next, *force;
+ int forceopt = FALSE;
+ /* Set peer channel variable */
+ varname = ast_strdupa(v->value);
+ next = varname;
+ if ((port = strchr(varname, ':'))) {
+ *port++ = '\0';
+ next = port;
+ }
+ if ((force = strchr(next, ','))) {
+ *force++ = '\0';
+ forceopt = strcmp(force, "force");
+ }
+ /* Allocate proxy object */
+ peer->outboundproxy = proxy_allocate(varname, port, forceopt);
+ } else if (!strcasecmp(v->name, "host")) {
if (!strcasecmp(v->value, "dynamic")) {
- if (!strcasecmp(v->name, "outboundproxy") || obproxyfound) {
- ast_log(LOG_WARNING, "You can't have a dynamic outbound proxy, you big silly head at line %d.\n", v->lineno);
- } else {
- /* They'll register with us */
- if (!found || !ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)) {
- /* Initialize stuff if this is a new peer, or if it used to be
- * non-dynamic before the reload. */
- memset(&peer->addr.sin_addr, 0, 4);
- if (peer->addr.sin_port) {
- /* If we've already got a port, make it the default rather than absolute */
- peer->defaddr.sin_port = peer->addr.sin_port;
- peer->addr.sin_port = 0;
- }
+ /* They'll register with us */
+ if (!found || !ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)) {
+ /* Initialize stuff iff we're not found, otherwise
+ we keep going with what we had */
+ memset(&peer->addr.sin_addr, 0, 4);
+ if (peer->addr.sin_port) {
+ /* If we've already got a port, make it the default rather than absolute */
+ peer->defaddr.sin_port = peer->addr.sin_port;
+ peer->addr.sin_port = 0;
}
ast_set_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC);
}
@@ -16752,19 +16875,13 @@
ASTOBJ_UNREF(peer_ptr, sip_destroy_peer);
}
ast_clear_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC);
- if (!obproxyfound || !strcasecmp(v->name, "outboundproxy")) {
- if (ast_get_ip_or_srv(&peer->addr, v->value, srvlookup ? "_sip._udp" : NULL)) {
- ASTOBJ_UNREF(peer, sip_destroy_peer);
- return NULL;
- }
+ if (ast_get_ip_or_srv(&peer->addr, v->value, srvlookup ? "_sip._udp" : NULL)) {
+ ASTOBJ_UNREF(peer, sip_destroy_peer);
+ return NULL;
}
- if (!strcasecmp(v->name, "outboundproxy"))
- obproxyfound=1;
- else {
- ast_copy_string(peer->tohost, v->value, sizeof(peer->tohost));
- if (!peer->addr.sin_port)
- peer->addr.sin_port = htons(STANDARD_SIP_PORT);
- }
+ ast_copy_string(peer->tohost, v->value, sizeof(peer->tohost));
+ if (!peer->addr.sin_port)
+ peer->addr.sin_port = htons(STANDARD_SIP_PORT);
}
} else if (!strcasecmp(v->name, "defaultip")) {
if (ast_get_ip(&peer->defaddr, v->value)) {
@@ -16901,7 +17018,6 @@
char *cat, *stringp, *context, *oldregcontext;
char newcontexts[AST_MAX_CONTEXT], oldcontexts[AST_MAX_CONTEXT];
struct hostent *hp;
- int format;
struct ast_flags dummy[2];
int auto_sip_domains = FALSE;
struct sockaddr_in old_bindaddr = bindaddr;
@@ -16964,8 +17080,9 @@
memset(&localaddr, 0, sizeof(localaddr));
memset(&externip, 0, sizeof(externip));
memset(&default_prefs, 0 , sizeof(default_prefs));
- outboundproxyip.sin_port = htons(STANDARD_SIP_PORT);
- outboundproxyip.sin_family = AF_INET; /* Type of address: IPv4 */
+ memset(&global_outboundproxy, 0, sizeof(struct sip_proxy));
+ global_outboundproxy.ip.sin_port = htons(STANDARD_SIP_PORT);
+ global_outboundproxy.ip.sin_family = AF_INET; /* Type of address: IPv4 */
ourport = STANDARD_SIP_PORT;
srvlookup = DEFAULT_SRVLOOKUP;
global_tos_sip = DEFAULT_TOS_SIP;
@@ -16974,7 +17091,6 @@
externhost[0] = '\0'; /* External host name (for behind NAT DynDNS support) */
externexpire = 0; /* Expiration for DNS re-issuing */
externrefresh = 10;
- memset(&outboundproxyip, 0, sizeof(outboundproxyip));
/* Reset channel settings to default before re-configuring */
allow_external_domains = DEFAULT_ALLOW_EXT_DOM; /* Allow external invites */
@@ -17144,12 +17260,20 @@
} else if (!strcasecmp(v->name, "fromdomain")) {
ast_copy_string(default_fromdomain, v->value, sizeof(default_fromdomain));
} else if (!strcasecmp(v->name, "outboundproxy")) {
- if (ast_get_ip_or_srv(&outboundproxyip, v->value, srvlookup ? "_sip._udp" : NULL) < 0)
- ast_log(LOG_WARNING, "Unable to locate host '%s'\n", v->value);
- } else if (!strcasecmp(v->name, "outboundproxyport")) {
- /* Port needs to be after IP */
- sscanf(v->value, "%d", &format);
- outboundproxyip.sin_port = htons(format);
+ char *name, *port = NULL, *force;
+
+ name = ast_strdupa(v->value);
+ if ((port = strchr(name, ':'))) {
+ *port++ = '\0';
+ global_outboundproxy.ip.sin_port = htons(atoi(port));
+ }
+
+ if ((force = strchr(port ? port : name, ','))) {
+ *force++ = '\0';
+ global_outboundproxy.force = (!strcasecmp(force, "force"));
+ }
+ ast_copy_string(global_outboundproxy.name, name, sizeof(global_outboundproxy.name));
+ proxy_update(&global_outboundproxy);
} else if (!strcasecmp(v->name, "autocreatepeer")) {
autocreatepeer = ast_true(v->value);
} else if (!strcasecmp(v->name, "srvlookup")) {
Modified: team/oej/obproxyfailover/configs/sip.conf.sample
URL: http://svn.digium.com/view/asterisk/team/oej/obproxyfailover/configs/sip.conf.sample?view=diff&rev=117261&r1=117260&r2=117261
==============================================================================
--- team/oej/obproxyfailover/configs/sip.conf.sample (original)
+++ team/oej/obproxyfailover/configs/sip.conf.sample Tue May 20 06:25:18 2008
@@ -135,6 +135,10 @@
; for Sipura and Grandstream ATAs, among others). This is
; contrary to the RFC3551 specification, the peer _should_
; be negotiating AAL2-G726-32 instead :-(
+
+;outboundproxy=proxy.provider.domain ; send outbound signaling to this proxy, not directly to the devices
+;outboundproxy=proxy.provider.domain:8080 ; send outbound signaling to this proxy, not directly to the devices
+;outboundproxy=proxy.provider.domain,force ; Send ALL outbound signalling to proxy, ignoring route: headers
;matchexterniplocally = yes ; Only substitute the externip or externhost setting if it matches
; your localnet setting. Unless you have some sort of strange network
@@ -517,6 +521,7 @@
;usereqphone=yes ; This provider requires ";user=phone" on URI
;call-limit=5 ; permit only 5 simultaneous outgoing calls to this peer
;outboundproxy=proxy.provider.domain ; send outbound signaling to this proxy, not directly to the peer
+;outboundproxy=proxy.provider.domain,force ; Send ALL outbound signalling to proxy, ignoring route: headers
; Call-limits will not be enforced on real-time peers,
; since they are not stored in-memory
;port=80 ; The port number we want to connect to on the remote side
More information about the asterisk-commits
mailing list