- feature: Outbound proxies configurable per domain

This commit is contained in:
Thomas Ries 2004-12-29 12:04:16 +00:00
parent aeff4536f2
commit f5a2a736a3
6 changed files with 129 additions and 32 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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 },

View File

@ -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<configuration.outbound_proxy_domain_name.used; i++) {
if (strcmp(configuration.outbound_proxy_domain_name.string[i],
domain)==0) {
sts = get_ip_by_host(configuration.outbound_proxy_domain_host.string[i],
addr);
if (sts == STS_FAILURE) {
ERROR("sip_find_outbound_proxy: cannot resolve "
"outbound proxy host [%s], check config",
configuration.outbound_proxy_domain_host.string[i]);
return STS_FAILURE;
}
*port=atoi(configuration.outbound_proxy_domain_port.string[i]);
if (*port == 0) *port = SIP_PORT;
return STS_SUCCESS;
} /* strcmp */
} /* for i */
}
/*
* now check for a global outbound proxy
*/
if (configuration.outbound_proxy_host) {
/* I have a global outbound proxy configured */
sts = get_ip_by_host(configuration.outbound_proxy_host, 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;
}
DEBUGC(DBCLASS_PROXY, "proxy_request: have outbound proxy %s:%i",
configuration.outbound_proxy_host, *port);
return STS_SUCCESS;
}
return STS_FAILURE; /* no proxy */
}

View File

@ -44,9 +44,9 @@ struct urlmap_s {
/*
* Array of strings - used withing configuration store
* Array of strings - used within configuration store
*/
#define CFG_STRARR_SIZE 128
#define CFG_STRARR_SIZE 128 /* max 128 entries in array */
typedef struct {
int used;
char *string[CFG_STRARR_SIZE];
@ -78,6 +78,9 @@ struct siproxd_config {
stringa_t masked_host;
char *outbound_proxy_host;
int outbound_proxy_port;
stringa_t outbound_proxy_domain_name;
stringa_t outbound_proxy_domain_host;
stringa_t outbound_proxy_domain_port;
char *registrationfile;
int log_calls;
char *pid_file;
@ -161,6 +164,8 @@ int sip_add_myvia (sip_ticket_t *ticket, int interface); /*X*/
int sip_del_myvia (sip_ticket_t *ticket); /*X*/
int sip_rewrite_contact (sip_ticket_t *ticket, int direction); /*X*/
int sip_calculate_branch_id (sip_ticket_t *ticket, char *id); /*X*/
int sip_find_outbound_proxy(sip_ticket_t *ticket, struct in_addr *addr,
int *port); /*X*/
/* readconf.c */
int read_config(char *name, int search); /*X*/