diff --git a/ChangeLog b/ChangeLog index 1f8be16..6a1ccdd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 0.5.10 ====== + 29-Dec-2004: - feature: Outbound proxies configurable per domain 08-Dec-2004: - make install will set siproxd_passwd.cfg to -rw----- 0.5.9 diff --git a/doc/siproxd.conf.example b/doc/siproxd.conf.example index 5bed7b4..260028c 100644 --- a/doc/siproxd.conf.example +++ b/doc/siproxd.conf.example @@ -184,3 +184,14 @@ debug_level = 0x00000000 # # outbound_proxy_host = my.outboundproxy.org # outbound_proxy_port = 5060 + +###################################################################### +# Outbound proxy (Provider specific) +# +# Outbound proxies can be specified on a per-domain base. +# This allows to use an outbound proxy needed for ProviderA +# and none (or another) for ProviderB. +# +#outbound_domain_name = freenet.de +#outbound_domain_host = proxy.for.domain.freende.de +#outbound_domain_port = 5060 diff --git a/src/proxy.c b/src/proxy.c index 67d2e4c..8e31cdb 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -449,24 +449,12 @@ int proxy_request (sip_ticket_t *ticket) { * 3) SIP URI */ /* - * fixed outbound proxy defined ? + * fixed or domain outbound proxy defined ? */ - if ((type == REQTYP_OUTGOING) && (configuration.outbound_proxy_host)) { - /* I have an outbound proxy configured */ - sts = get_ip_by_host(configuration.outbound_proxy_host, &sendto_addr); - if (sts == STS_FAILURE) { - DEBUGC(DBCLASS_PROXY, "proxy_request: cannot resolve outbound " - " proxy host [%s]", configuration.outbound_proxy_host); - return STS_FAILURE; - } - - if (configuration.outbound_proxy_port) { - port=configuration.outbound_proxy_port; - } else { - port = SIP_PORT; - } + if ((type == REQTYP_OUTGOING) && + (sip_find_outbound_proxy(ticket, &sendto_addr, &port) == STS_SUCCESS)) { DEBUGC(DBCLASS_PROXY, "proxy_request: have outbound proxy %s:%i", - configuration.outbound_proxy_host, port); + utils_inet_ntoa(sendto_addr), port); /* * Route present? * If so, fetch address from topmost Route: header and remove it. @@ -883,20 +871,10 @@ int proxy_response (sip_ticket_t *ticket) { /* * check if we need to send to an outbound proxy */ - if ((type == RESTYP_OUTGOING) && (configuration.outbound_proxy_host)) { - /* have an outbound proxy - use it to send the packet */ - sts = get_ip_by_host(configuration.outbound_proxy_host, &sendto_addr); - if (sts == STS_FAILURE) { - DEBUGC(DBCLASS_PROXY, "proxy_response: cannot resolve outbound " - " proxy host [%s]", configuration.outbound_proxy_host); - return STS_FAILURE; - } - - if (configuration.outbound_proxy_port) { - port=configuration.outbound_proxy_port; - } else { - port = SIP_PORT; - } + if ((type == RESTYP_OUTGOING) && + (sip_find_outbound_proxy(ticket, &sendto_addr, &port) == STS_SUCCESS)) { + DEBUGC(DBCLASS_PROXY, "proxy_response: have outbound proxy %s:%i", + utils_inet_ntoa(sendto_addr), port); /* * Route present? * If so, fetch address from topmost Route: header and remove it. diff --git a/src/readconf.c b/src/readconf.c index 4ac9ea3..ac24a47 100644 --- a/src/readconf.c +++ b/src/readconf.c @@ -166,6 +166,9 @@ static int parse_config (FILE *configfile) { { "masked_host", TYP_STRINGA,&configuration.masked_host }, { "outbound_proxy_host", TYP_STRING, &configuration.outbound_proxy_host }, { "outbound_proxy_port", TYP_INT4, &configuration.outbound_proxy_port }, + { "outbound_domain_name",TYP_STRINGA,&configuration.outbound_proxy_domain_name }, + { "outbound_domain_host",TYP_STRINGA,&configuration.outbound_proxy_domain_host }, + { "outbound_domain_port",TYP_STRINGA,&configuration.outbound_proxy_domain_port }, { "registration_file", TYP_STRING ,&configuration.registrationfile }, { "log_calls", TYP_INT4, &configuration.log_calls }, { "pid_file", TYP_STRING ,&configuration.pid_file }, diff --git a/src/sip_utils.c b/src/sip_utils.c index 1ba5de1..5dc4188 100644 --- a/src/sip_utils.c +++ b/src/sip_utils.c @@ -871,3 +871,102 @@ int sip_calculate_branch_id (sip_ticket_t *ticket, char *id) { return STS_SUCCESS; } + + +/* + * SIP_FIND_OUTBOUND_PROXY + * + * performs the lookup for an apropriate outbound proxy + * + * RETURNS + * STS_SUCCESS on successful lookup + * STS_FAILURE if no outbound proxy to be used + */ +int sip_find_outbound_proxy(sip_ticket_t *ticket, struct in_addr *addr, + int *port) { + int i, sts; + char *domain=NULL; + osip_message_t *sipmsg; + + sipmsg=ticket->sipmsg; + + if (!addr ||!port) { + ERROR("sip_find_outbound_proxy called with NULL addr or port"); + return STS_FAILURE; + } + + if (sipmsg && sipmsg->from && sipmsg->from->url) { + domain=sipmsg->from->url->host; + } + + if (domain == NULL) { + WARN("sip_find_outbound_proxy called with NULL from->url->host"); + return STS_FAILURE; + } + + /* + * check consistency of configuration: + * outbound_domain_name, outbound_domain_host, outbound_domain_port + * must match up + */ + if ((configuration.outbound_proxy_domain_name.used != + configuration.outbound_proxy_domain_host.used) || + (configuration.outbound_proxy_domain_name.used != + configuration.outbound_proxy_domain_port.used)) { + ERROR("configuration of outbound_domain_ inconsistent, check config"); + } else { + /* + * perform the lookup for domain specific proxies + * first match wins + */ + for (i=0; i