- small enhancements in error checking
This commit is contained in:
+18
-12
@@ -127,9 +127,17 @@ int proxy_request (sip_ticket_t *ticket) {
|
||||
route = (osip_route_t *) osip_list_get(request->routes, 0);
|
||||
|
||||
sts = get_ip_by_host(route->url->host, &addr1);
|
||||
get_ip_by_ifname(configuration.inbound_if, &addr2);
|
||||
get_ip_by_ifname(configuration.outbound_if, &addr3);
|
||||
|
||||
if (get_ip_by_ifname(configuration.inbound_if, &addr2) != STS_SUCCESS) {
|
||||
ERROR("can't find inbound interface %s - configuration error?",
|
||||
configuration.inbound_if);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &addr3)!= STS_SUCCESS) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
|
||||
/* my own route header? */
|
||||
if ((sts == STS_SUCCESS) &&
|
||||
((memcmp(&addr1, &addr2, sizeof(addr1)) == 0) ||
|
||||
@@ -450,16 +458,14 @@ int proxy_request (sip_ticket_t *ticket) {
|
||||
*/
|
||||
switch (type) {
|
||||
case REQTYP_INCOMING:
|
||||
sts = get_ip_by_ifname(configuration.inbound_if, &addr);
|
||||
if (sts == STS_FAILURE) {
|
||||
if (get_ip_by_ifname(configuration.inbound_if, &addr) != STS_SUCCESS) {
|
||||
ERROR("can't find inbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
configuration.inbound_if);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
break;
|
||||
case REQTYP_OUTGOING:
|
||||
sts = get_ip_by_ifname(configuration.outbound_if, &addr);
|
||||
if (sts == STS_FAILURE) {
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &addr) != STS_SUCCESS) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
return STS_FAILURE;
|
||||
@@ -1004,8 +1010,8 @@ if (configuration.debuglevel)
|
||||
*/
|
||||
|
||||
/* get outbound address */
|
||||
sts = get_ip_by_ifname(configuration.outbound_if, &outside_addr);
|
||||
if (sts == STS_FAILURE) {
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &outside_addr) !=
|
||||
STS_SUCCESS) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
sdp_message_free(sdp);
|
||||
@@ -1013,8 +1019,8 @@ if (configuration.debuglevel)
|
||||
}
|
||||
|
||||
/* get inbound address */
|
||||
sts = get_ip_by_ifname(configuration.inbound_if, &inside_addr);
|
||||
if (sts == STS_FAILURE) {
|
||||
if (get_ip_by_ifname(configuration.inbound_if, &inside_addr) !=
|
||||
STS_SUCCESS) {
|
||||
ERROR("can't find inbound interface %s - configuration error?",
|
||||
configuration.inbound_if);
|
||||
sdp_message_free(sdp);
|
||||
|
||||
+6
-1
@@ -366,7 +366,12 @@ int register_client(sip_ticket_t *ticket, int force_lcl_masq) {
|
||||
if (force_lcl_masq) {
|
||||
struct in_addr addr;
|
||||
char *addrstr;
|
||||
sts = get_ip_by_ifname(configuration.outbound_if,&addr);
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &addr) !=
|
||||
STS_SUCCESS) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
addrstr = utils_inet_ntoa(addr);
|
||||
DEBUGC(DBCLASS_REG,"masquerading UA %s@%s local %s@%s",
|
||||
(url1_contact->username) ? url1_contact->username : "*NULL*",
|
||||
|
||||
+11
-7
@@ -208,7 +208,10 @@ int is_via_local (osip_via_t *via) {
|
||||
|
||||
if (ptr) {
|
||||
DEBUGC(DBCLASS_BABBLE,"resolving IP of interface %s",ptr);
|
||||
sts = get_ip_by_ifname(ptr, &addr_myself);
|
||||
if (get_ip_by_ifname(ptr, &addr_myself) != STS_SUCCESS) {
|
||||
ERROR("can't find interface %s - configuration error?", ptr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* check the extracted VIA against my own host addresses */
|
||||
@@ -424,7 +427,10 @@ int is_sipuri_local (sip_ticket_t *ticket) {
|
||||
|
||||
if (ptr) {
|
||||
DEBUGC(DBCLASS_BABBLE,"resolving IP of interface %s",ptr);
|
||||
sts = get_ip_by_ifname(ptr, &addr_myself);
|
||||
if (get_ip_by_ifname(ptr, &addr_myself) != STS_SUCCESS) {
|
||||
ERROR("can't find interface %s - configuration error?", ptr);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* check the extracted HOST against my own host addresses */
|
||||
@@ -599,15 +605,13 @@ int sip_add_myvia (sip_ticket_t *ticket, int interface) {
|
||||
char branch_id[VIA_BRANCH_SIZE];
|
||||
|
||||
if (interface == IF_OUTBOUND) {
|
||||
sts = get_ip_by_ifname(configuration.outbound_if, &addr);
|
||||
if (sts == STS_FAILURE) {
|
||||
ERROR("can't find outbound interface %s - configuration error?",
|
||||
if (get_ip_by_ifname(configuration.outbound_if, &addr) != STS_SUCCESS) {
|
||||
ERROR("can't find interface %s - configuration error?",
|
||||
configuration.outbound_if);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
} else {
|
||||
sts = get_ip_by_ifname(configuration.inbound_if, &addr);
|
||||
if (sts == STS_FAILURE) {
|
||||
if (get_ip_by_ifname(configuration.inbound_if, &addr) != STS_SUCCESS) {
|
||||
ERROR("can't find inbound interface %s - configuration error?",
|
||||
configuration.inbound_if);
|
||||
return STS_FAILURE;
|
||||
|
||||
+20
-13
@@ -379,22 +379,29 @@ int main (int argc, char *argv[])
|
||||
struct in_addr addr1, addr2, addr3;
|
||||
|
||||
url = osip_message_get_uri(ticket.sipmsg);
|
||||
sts = get_ip_by_host(url->host, &addr1);
|
||||
|
||||
get_ip_by_ifname(configuration.inbound_if,&addr2);
|
||||
get_ip_by_ifname(configuration.outbound_if,&addr3);
|
||||
if ( (get_ip_by_host(url->host, &addr1) == STS_SUCCESS) &&
|
||||
(get_ip_by_ifname(configuration.inbound_if,&addr2) ==
|
||||
STS_SUCCESS) &&
|
||||
(get_ip_by_ifname(configuration.outbound_if,&addr3) ==
|
||||
STS_SUCCESS)) {
|
||||
|
||||
if ((sts == STS_SUCCESS) &&
|
||||
((memcmp(&addr1, &addr2, sizeof(addr1)) == 0) ||
|
||||
(memcmp(&addr1, &addr3, sizeof(addr1)) == 0))) {
|
||||
/* I'm the registrar, send response myself */
|
||||
sts = register_client(&ticket, 0);
|
||||
sts = register_response(&ticket, sts);
|
||||
if ((memcmp(&addr1, &addr2, sizeof(addr1)) == 0) ||
|
||||
(memcmp(&addr1, &addr3, sizeof(addr1)) == 0)) {
|
||||
/* I'm the registrar, send response myself */
|
||||
sts = register_client(&ticket, 0);
|
||||
sts = register_response(&ticket, sts);
|
||||
} else {
|
||||
/* I'm just the outbound proxy */
|
||||
DEBUGC(DBCLASS_SIP,"proxying REGISTER request to:%s",
|
||||
url->host);
|
||||
sts = register_client(&ticket, 1);
|
||||
sts = proxy_request(&ticket);
|
||||
}
|
||||
} else {
|
||||
/* I'm just the outbound proxy */
|
||||
DEBUGC(DBCLASS_SIP,"proxying REGISTER request to:%s",url->host);
|
||||
sts = register_client(&ticket, 1);
|
||||
sts = proxy_request(&ticket);
|
||||
if (MSG_IS_REQUEST(ticket.sipmsg)) {
|
||||
sip_gen_response(&ticket, 408 /*request timeout*/);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
WARN("non-authorized registration attempt from %s",
|
||||
|
||||
+6
-3
@@ -135,7 +135,7 @@ int get_ip_by_host(char *hostname, struct in_addr *addr) {
|
||||
hostentry = gethostbyname_r(hostname, /* the FQDN */
|
||||
&result_buffer, /* the result buffer */
|
||||
tmp,
|
||||
GETHOSTBYNAME_BUFLEN - 1,
|
||||
GETHOSTBYNAME_BUFLEN,
|
||||
&error);
|
||||
|
||||
/* gethostbyname_r() with 6 arguments (e.g. linux glibc) */
|
||||
@@ -143,7 +143,7 @@ int get_ip_by_host(char *hostname, struct in_addr *addr) {
|
||||
gethostbyname_r(hostname, /* the FQDN */
|
||||
&result_buffer, /* the result buffer */
|
||||
tmp,
|
||||
GETHOSTBYNAME_BUFLEN - 1,
|
||||
GETHOSTBYNAME_BUFLEN,
|
||||
&hostentry,
|
||||
&error);
|
||||
#else
|
||||
@@ -325,6 +325,8 @@ int get_ip_by_ifname(char *ifname, struct in_addr *retaddr) {
|
||||
cache_initialized=1;
|
||||
}
|
||||
|
||||
if (retaddr) memset(retaddr, 0, sizeof(struct in_addr));
|
||||
|
||||
time(&t);
|
||||
/* clean expired entries */
|
||||
for (i=0; i<IFADR_CACHE_SIZE; i++) {
|
||||
@@ -372,7 +374,8 @@ int get_ip_by_ifname(char *ifname, struct in_addr *retaddr) {
|
||||
|
||||
/* get address */
|
||||
if(ioctl(sockfd, SIOCGIFADDR, &ifr) != 0) {
|
||||
ERROR("Error in ioctl SIOCGIFADDR: %s\n",strerror(errno));
|
||||
ERROR("Error in ioctl SIOCGIFADDR: %s (interface %s)\n",
|
||||
strerror(errno), ifname);
|
||||
close(sockfd);
|
||||
return STS_FAILURE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user