[sr-dev] git:master: ims_*_pcscf: Several bugfixes

Carsten Bock carsten at ng-voice.com
Wed Sep 10 17:34:14 CEST 2014


Module: sip-router
Branch: master
Commit: a2cf37e0edc89f5bef9ae193122053de4652249f
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a2cf37e0edc89f5bef9ae193122053de4652249f

Author: Carsten Bock <carsten at ng-voice.com>
Committer: Carsten Bock <carsten at ng-voice.com>
Date:   Wed Sep 10 17:32:40 2014 +0200

ims_*_pcscf: Several bugfixes

---

 modules/ims_registrar_pcscf/service_routes.c |   46 ++++++++++++++++----------
 modules/ims_usrloc_pcscf/udomain.c           |    8 +++--
 2 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/modules/ims_registrar_pcscf/service_routes.c b/modules/ims_registrar_pcscf/service_routes.c
index 1b2371b..4380ce8 100644
--- a/modules/ims_registrar_pcscf/service_routes.c
+++ b/modules/ims_registrar_pcscf/service_routes.c
@@ -112,6 +112,11 @@ int checkcontact(struct sip_msg* _m, pcontact_t * c) {
 	str received_host = {0, 0};
 	char srcip[50];	
 
+	LM_DBG("Port %d (search %d), Proto %d (search %d), reg_state %s (search %s)\n",
+		c->received_port, _m->rcv.src_port, c->received_proto, _m->rcv.proto,
+		reg_state_to_string(c->reg_state), reg_state_to_string(PCONTACT_REGISTERED)
+	);
+
 	if (c->security) {
 		switch (c->security->type) {
 		case SECURITY_IPSEC:
@@ -164,7 +169,6 @@ pcontact_t * getContactP(struct sip_msg* _m, udomain_t* _d) {
 	str received_host = {0, 0};
 	char srcip[50];	
 
-
 	if (_m->id != current_msg_id) {
 		current_msg_id = _m->id;
 		c = NULL;
@@ -172,10 +176,17 @@ pcontact_t * getContactP(struct sip_msg* _m, udomain_t* _d) {
 		if (is_registered_fallback2ip == 2) {
 			received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
 			received_host.s = srcip;
-			if (ul.get_pcontact_by_src(_d, &received_host, _m->rcv.src_port, _m->rcv.proto, &c) == 1)
+
+			LM_DBG("Searching in usrloc for %.*s:%i (Proto %i)\n",
+				received_host.len, received_host.s,
+				_m->rcv.src_port, _m->rcv.proto);
+
+			if (ul.get_pcontact_by_src(_d, &received_host, _m->rcv.src_port, _m->rcv.proto, &c) == 1) {
 				LM_DBG("No entry in usrloc for %.*s:%i (Proto %i) found!\n", received_host.len, received_host.s, _m->rcv.src_port, _m->rcv.proto);
-			if (checkcontact(_m, c) != 0) {
-				c = NULL;
+			} else {
+				if (checkcontact(_m, c) != 0) {
+					c = NULL;
+				}
 			}
 		}
 
@@ -185,10 +196,10 @@ pcontact_t * getContactP(struct sip_msg* _m, udomain_t* _d) {
 			if (b && b->contacts) {
 				for (ct = b->contacts; ct; ct = ct->next) {
 					if (ul.get_pcontact(_d, &ct->uri, &c) == 0) {
-						if (checkcontact(_m, c) == 0) {
-							break;
-						} else {
+						if (checkcontact(_m, c) != 0) {
 							c = NULL;
+						} else {
+							break;
 						}
 					}
 				}
@@ -201,10 +212,12 @@ pcontact_t * getContactP(struct sip_msg* _m, udomain_t* _d) {
 			LM_INFO("Contact not found based on Contact-header, trying IP/Port/Proto\n");
 			received_host.len = ip_addr2sbuf(&_m->rcv.src_ip, srcip, sizeof(srcip));
 			received_host.s = srcip;
-			if (ul.get_pcontact_by_src(_d, &received_host, _m->rcv.src_port, _m->rcv.proto, &c) == 1)
+			if (ul.get_pcontact_by_src(_d, &received_host, _m->rcv.src_port, _m->rcv.proto, &c) == 1) {
 				LM_DBG("No entry in usrloc for %.*s:%i (Proto %i) found!\n", received_host.len, received_host.s, _m->rcv.src_port, _m->rcv.proto);
-			if (checkcontact(_m, c) != 0) {
-				c = NULL;
+			} else {
+				if (checkcontact(_m, c) != 0) {
+					c = NULL;
+				}
 			}
 		}
 	}
@@ -308,7 +321,7 @@ int check_service_routes(struct sip_msg* _m, udomain_t* _d) {
 
 				/* No more Route-Headers? Not following service-routes */
 				if (!r) {
-					LM_ERR("No more route headers in message.\n");
+					LM_DBG("No more route headers in message.\n");
 					 goto error;
 				}
 				
@@ -330,7 +343,7 @@ int check_service_routes(struct sip_msg* _m, udomain_t* _d) {
 
 			/* Check, if it was the last route-header in the message: */
 			if (r) {
-				LM_ERR("Too many route headers in message.\n");
+				LM_DBG("Too many route headers in message.\n");
 				 goto error;
 			}
 		} else {
@@ -338,7 +351,7 @@ int check_service_routes(struct sip_msg* _m, udomain_t* _d) {
 			if (c->num_service_routes > 0) goto error;
 		}
 	} else {
-		LM_ERR("No route header in Message.\n");
+		LM_DBG("No route header in Message.\n");
 		/* No route-header? Check, if service-routes are indicated.
 		   If yes, request is not following service-routes */
 		if (c->num_service_routes > 0) goto error;
@@ -352,12 +365,10 @@ error:
 	return -1;
 }
 
-static str route_start={": <",8};
+static str route_start={"Route: <",8};
 static str route_sep={">, <",4};
 static str route_end={">\r\n",3};
 
-extern str route_header;
-
 /**
  * Force Service routes (upon request)
  */
@@ -408,7 +419,7 @@ int force_service_routes(struct sip_msg* _m, udomain_t* _d) {
 			goto error;
 		}	
 		/* Calculate the length: */
-		new_route_header.len = route_header.len + route_start.len +
+		new_route_header.len = route_start.len +
 			route_end.len + (c->num_service_routes-1) * route_sep.len;
 
 		for(i=0; i< c->num_service_routes; i++)
@@ -422,7 +433,6 @@ int force_service_routes(struct sip_msg* _m, udomain_t* _d) {
 		
 		/* Construct new header */
 		new_route_header.len = 0;
-		STR_APPEND(new_route_header, route_header);
 		STR_APPEND(new_route_header, route_start);
 		for(i=0; i < c->num_service_routes; i++) {
 			if (i) STR_APPEND(new_route_header, route_sep);
diff --git a/modules/ims_usrloc_pcscf/udomain.c b/modules/ims_usrloc_pcscf/udomain.c
index 3e7aa63..23e1213 100644
--- a/modules/ims_usrloc_pcscf/udomain.c
+++ b/modules/ims_usrloc_pcscf/udomain.c
@@ -481,15 +481,15 @@ int get_pcontact(udomain_t* _d, str* _contact, struct pcontact** _c) {
 		LM_DBG("Searching for [%.*s] and comparing to [%.*s]\n", _contact->len, _contact->s, c->aor.len, c->aor.s);
 
 		/* hosts HAVE to match */
-		if (lookup_check_received && ((needle_uri.host.len != c->received_host.len) || (memcmp(needle_uri.host.s, c->contact_host.s, needle_uri.host.len)!=0))) {
+		if (lookup_check_received && ((needle_uri.host.len != c->received_host.len) || (memcmp(needle_uri.host.s, c->received_host.s, needle_uri.host.len)!=0))) {
 			//can't possibly match
+			LM_DBG("Lookup failed for [%.*s <=> %.*s]\n", needle_uri.host.len, needle_uri.host.s, c->received_host.len, c->received_host.s);
 			c = c->next;
 			continue;
 		}
 
 		/* one of the ports must match, either the initial registered port, the received port, or one if the security ports (server) */
-		if ((needle_uri.port_no != c->contact_port)
-				&& (needle_uri.port_no != c->received_proto)) {
+		if ((needle_uri.port_no != c->contact_port) && (needle_uri.port_no != c->received_port)) {
 			//check security ports
 			if (c->security) {
 				switch (c->security->type) {
@@ -536,6 +536,8 @@ int get_pcontact(udomain_t* _d, str* _contact, struct pcontact** _c) {
 		}
 
 		if (!port_match){
+			LM_DBG("Port don't match: %d (contact) %d (received) != %d!\n",
+		c->contact_port, c->received_port, needle_uri.port_no);
 			c = c->next;
 			continue;
 		}




More information about the sr-dev mailing list