diff --git a/ChangeLog b/ChangeLog index d8be253..acd1d4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 0.6.1 ===== + 22-Nov-2007: - Working on code that that will allow siproxd to use + separate interfaces in its "in front of NAT routes" setup. + ( UA1[LAN0]--siproxd--LAN1--NAT--Internet--UA2 ) 12-Nov-2007: - Small changes to compile again under OpenBSD. 0.6.0 diff --git a/src/proxy.c b/src/proxy.c index 46bd4eb..921fb83 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1078,15 +1078,22 @@ if (configuration.debuglevel) /* * Am I running in front of the routing device? Then I cannot - * use the external IP to bind a listen socket to, so force - * the use of my inbound IP for listening. + * use the external IP to bind a listen socket to, but should + * use my real IP on the outbound interface (which may legally + * be the same as the inbound interface if only one interface + * is used). */ if ((rtp_direction == DIR_INCOMING) && (configuration.outbound_host) && (strcmp(configuration.outbound_host, "")!=0)) { DEBUGC(DBCLASS_PROXY, "proxy_rewrite_invitation_body: " - "in-front-of-NAT-Router"); - memcpy(&map_addr, &inside_addr, sizeof (map_addr)); + "in-front-of-NAT-Router, use real outboud IP"); + if (get_interface_real_ip(IF_OUTBOUND, &map_addr) + != STS_SUCCESS) { + ERROR("cannot get my real outbound interface address"); + /* as we do not know better, take the internal address */ + memcpy(&map_addr, &inside_addr, sizeof (map_addr)); + } } sts = rtp_start_fwd(osip_message_get_call_id(mymsg), diff --git a/src/sip_utils.c b/src/sip_utils.c index f84ab01..d4c590b 100644 --- a/src/sip_utils.c +++ b/src/sip_utils.c @@ -223,7 +223,7 @@ int is_via_local (osip_via_t *via) { continue; } } else { - /* check againt a possible defined 'host_outbound' */ + /* check against a possible defined 'host_outbound' */ DEBUGC(DBCLASS_BABBLE,"resolving IP of interface ''host_outbound'"); /* defined? */ if (configuration.outbound_host == NULL) continue; diff --git a/src/siproxd.h b/src/siproxd.h index c7734da..f239141 100644 --- a/src/siproxd.h +++ b/src/siproxd.h @@ -173,6 +173,7 @@ int get_ip_by_host(char *hostname, struct in_addr *addr); /*X*/ void secure_enviroment (void); int get_ip_by_ifname(char *ifname, struct in_addr *retaddr); /*X*/ int get_interface_ip(int interface, struct in_addr *retaddr); /*X*/ +int get_interface_real_ip(int interface, struct in_addr *retaddr); /*X*/ char *utils_inet_ntoa(struct in_addr in); int utils_inet_aton(const char *cp, struct in_addr *inp); int createpidfile(char *pidfilename); /*X*/ diff --git a/src/utils.c b/src/utils.c index e9af269..17ba8a5 100644 --- a/src/utils.c +++ b/src/utils.c @@ -315,19 +315,13 @@ void secure_enviroment (void) { /* * get_interface_ip: * fetches own IP address by interface INBOUND/OUTBOUND + * takes into account a possible outbound_host setting. * * STS_SUCCESS on returning a valid IP and interface is UP * STS_FAILURE if interface is DOWN or other problem */ int get_interface_ip(int interface, struct in_addr *retaddr) { int sts=STS_FAILURE; - char *tmp=NULL; - - if (interface == IF_INBOUND) { - tmp = configuration.inbound_if; - } else if (interface == IF_OUTBOUND) { - tmp = configuration.outbound_if; - } if ((interface == IF_OUTBOUND) && (configuration.outbound_host) && @@ -339,7 +333,32 @@ int get_interface_ip(int interface, struct in_addr *retaddr) { sts = STS_SUCCESS; } - } else if (tmp && (strcmp(tmp, "")!=0)) { + } else { + sts = get_interface_real_ip(interface, retaddr); + } + + return sts; +} + + +/* + * get_interface_real_ip: + * fetches the real IP address of my interface INBOUND/OUTBOUND + * + * STS_SUCCESS on returning a valid IP and interface is UP + * STS_FAILURE if interface is DOWN or other problem + */ +int get_interface_real_ip(int interface, struct in_addr *retaddr) { + int sts=STS_FAILURE; + char *tmp=NULL; + + if (interface == IF_INBOUND) { + tmp = configuration.inbound_if; + } else if (interface == IF_OUTBOUND) { + tmp = configuration.outbound_if; + } + + if (tmp && (strcmp(tmp, "")!=0)) { DEBUGC(DBCLASS_DNS, "fetching interface IP by INTERFACE [%i]", interface); sts = get_ip_by_ifname(tmp, retaddr); if (sts != STS_SUCCESS) {