From 9ed7689e4e0823f0bf6e7780a40aeae204637a03 Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Thu, 7 Jan 2010 11:06:41 +0000 Subject: [PATCH] - Better handling of matching the local UAs --- ChangeLog | 3 +- src/sip_utils.c | 80 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 56 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c55ab1..89749bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,10 @@ 0.7.3 ===== + 07-Jan-2010: - Better handling of matching the local UAs + 15-Dec-2009: - Better handling for SIP redirecting with newer kernels 28-Oct-2009: - Make local UA to local UA calls work better with UAs that blindly practice symmetric RTP and ignore the SDP media description completely. - 15-Dec-2009: - Better handling for SIP redirecting with newer kernels 0.7.2 ===== diff --git a/src/sip_utils.c b/src/sip_utils.c index bc2e4ee..2d0ed69 100644 --- a/src/sip_utils.c +++ b/src/sip_utils.c @@ -979,9 +979,22 @@ int sip_find_direction(sip_ticket_t *ticket, int *urlidx) { ticket->direction = DIRTYP_UNKNOWN; + /* Search order is as follows: + * - "from" IP address one of our registered local UAs + * - "To:" SIP header (Request) directed to internal UA + * or + * "From:" SIP header (Response) coming from internal UA + * - SIP URI matches one of the registered local UAs + * - for Responses: check for bottommost "Via:" header to be + * one of our registered local UA IPs + * - "from" IP == 127.0.0.1 || inbound_IP || outbound IP + * + * The first successful match is taken. + */ + /* * did I receive the telegram from a REGISTERED host? - * -> it must be an OUTGOING request + * -> it must be an OUTGOING request/response */ for (i=0; i it must be an INCOMING request + * -> likely to be an INCOMING request/response + * check for a match on the To: header first */ if (type == DIRTYP_UNKNOWN) { for (i=0; isipmsg)) { /* REQUEST */ - /* incoming request (SIP URI == 'masq') || ((SIP URI == 'reg') && !REGISTER)*/ - if ((compare_url(request->req_uri, urlmap[i].masq_url)==STS_SUCCESS) || - (!MSG_IS_REGISTER(request) && - (compare_url(request->req_uri, urlmap[i].reg_url)==STS_SUCCESS))) { - type=REQTYP_INCOMING; - break; - } /* incoming request ('to' == 'masq') || (('to' == 'reg') && !REGISTER)*/ if ((compare_url(request->to->url, urlmap[i].masq_url)==STS_SUCCESS) || (!MSG_IS_REGISTER(request) && @@ -1050,17 +1057,37 @@ int sip_find_direction(sip_ticket_t *ticket, int *urlidx) { } /* for i */ } /* if type == DIRTYP_UNKNOWN */ - if (MSG_IS_RESPONSE(ticket->sipmsg)) { - /* &&&& Open Issue &&&& - it has been seen with cross-provider calls that the FROM may be 'garbled' - (e.g 1393xxx@proxy01.sipphone.com for calls made sipphone -> FWD) - How can we deal with this? Should I take into consideration the 'Via' - headers? This is the only clue I have, pointing to the *real* UA. - Maybe I should put in a 'siproxd' ftag value to recognize it as a header - inserted by myself - */ - if ((type == DIRTYP_UNKNOWN) && - (!osip_list_eol(&(response->vias), 0))) { + + /* + * nothing found yet? + * -> likely to be an INCOMING request/response + * check for a match on the SIP URI (requests only) + */ + if ((type == DIRTYP_UNKNOWN) && (MSG_IS_REQUEST(ticket->sipmsg))) { + for (i=0; ireq_uri, urlmap[i].masq_url)==STS_SUCCESS) || + (!MSG_IS_REGISTER(request) && + (compare_url(request->req_uri, urlmap[i].reg_url)==STS_SUCCESS))) { + type=REQTYP_INCOMING; + break; + } + } /* for i */ + } /* if type == DIRTYP_UNKNOWN */ + + + /* &&&& Open Issue &&&& + * it has been seen with cross-provider calls that the FROM may be 'garbled' + * (e.g 1393xxx@proxy01.sipphone.com for calls made sipphone -> FWD) + * How can we deal with this? Should I take into consideration the 'Via' + * headers? This is the only clue I have, pointing to the *real* UA. + * Maybe I should put in a 'siproxd' ftag value to recognize it as a header + * inserted by myself + */ + if ((type == DIRTYP_UNKNOWN) && + (!osip_list_eol(&(response->vias), 0))) { + if (MSG_IS_RESPONSE(ticket->sipmsg)) { osip_via_t *via; struct in_addr addr_via, addr_myself; int port_via, port_ua; @@ -1106,8 +1133,9 @@ int sip_find_direction(sip_ticket_t *ticket, int *urlidx) { } } /* for i */ } - } /* if type == DIRTYP_UNKNOWN */ - } /* is response */ + } /* is response */ + } /* if type == DIRTYP_UNKNOWN */ + /* * if the telegram is received from 127.0.0.1 use my inbound IP as sender, @@ -1131,7 +1159,7 @@ int sip_find_direction(sip_ticket_t *ticket, int *urlidx) { type=RESTYP_OUTGOING; } } - } + } /* if type == DIRTYP_UNKNOWN */ if (type == DIRTYP_UNKNOWN) {