From 5b310dd9db9ed2972b2b46dd82fce55b4bcb316f Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Sun, 13 Jun 2004 20:48:57 +0000 Subject: [PATCH] - small enhancements in error checking --- src/proxy.c | 30 ++++++++++++++++++------------ src/register.c | 7 ++++++- src/sip_utils.c | 18 +++++++++++------- src/siproxd.c | 33 ++++++++++++++++++++------------- src/utils.c | 9 ++++++--- 5 files changed, 61 insertions(+), 36 deletions(-) diff --git a/src/proxy.c b/src/proxy.c index 63837a4..83549b3 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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); diff --git a/src/register.c b/src/register.c index 06a3928..d40b18a 100644 --- a/src/register.c +++ b/src/register.c @@ -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*", diff --git a/src/sip_utils.c b/src/sip_utils.c index 5366ca4..1b90db6 100644 --- a/src/sip_utils.c +++ b/src/sip_utils.c @@ -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; diff --git a/src/siproxd.c b/src/siproxd.c index c5ca452..946f4a2 100644 --- a/src/siproxd.c +++ b/src/siproxd.c @@ -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", diff --git a/src/utils.c b/src/utils.c index 20ff99f..ca7506e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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