瀏覽代碼

modules/ims_qos:
Use same framed-ip-address and subscription-id through Rx session
Save framed-ip-address and subscription-id for initial Rx AAR and re-use for
subsequent AARs in the same Rx session

Richard Good 11 年之前
父節點
當前提交
72ddccb2aa
共有 4 個文件被更改,包括 107 次插入32 次删除
  1. 79 2
      modules/ims_qos/mod.c
  2. 9 27
      modules/ims_qos/rx_aar.c
  3. 16 2
      modules/ims_qos/rx_authdata.c
  4. 3 1
      modules/ims_qos/rx_authdata.h

+ 79 - 2
modules/ims_qos/mod.c

@@ -69,6 +69,7 @@
 #include "rx_str.h"
 #include "rx_aar.h"
 #include "mod.h"
+#include "../../parser/sdp/sdp.h"
 
 #include "../../lib/ims/useful_defs.h"
 
@@ -387,6 +388,9 @@ static int w_rx_aar(struct sip_msg *msg, char *route, char* str1, char* bar) {
     str ttag = {0, 0};
     
     str route_name;
+    str identifier, ip;
+    int must_free_asserted_identity = 0;
+    sdp_session_cell_t* sdp_session;
 
     cfg_action_t* cfg_action = 0;
     saved_transaction_t* saved_t_data = 0; //data specific to each contact's AAR async call
@@ -524,12 +528,79 @@ static int w_rx_aar(struct sip_msg *msg, char *route, char* str1, char* bar) {
 
     if (!rx_session_id || rx_session_id->len <= 0 || !rx_session_id->s) {
         LM_DBG("New AAR session for this dialog in mode %s\n", direction);
-        //create new diameter auth session
-        int ret = create_new_callsessiondata(&callid, &ftag, &ttag, &rx_authdata_p);
+        
+	
+	//get ip and subscription_id and store them in the call session data
+	
+	//SUBSCRIPTION-ID
+	//if its mo we use p_asserted_identity in request - if that not there we use from_uri
+	//if its mt we use p_asserted_identity in reply - if that not there we use to_uri
+	//IP 
+	//if its mo we use request SDP
+	//if its mt we use reply SDP
+	if (dlg_direction == DLG_MOBILE_ORIGINATING) {
+	    LM_DBG("originating direction\n");
+	    if ((identifier = cscf_get_asserted_identity(t->uas.request, 1)).len == 0) {
+		LM_DBG("No P-Asserted-Identity hdr found in request. Using From hdr in req");
+
+		if (!cscf_get_from_uri(t->uas.request, &identifier)) {
+			LM_ERR("Error assigning P-Asserted-Identity using From hdr in req");
+			goto error;
+		}
+	    } else {
+		must_free_asserted_identity = 1;
+	    }
+	    
+	    //get ip from request sdp (we use first SDP session)
+	    if (parse_sdp(t->uas.request) < 0) {
+		LM_ERR("Unable to parse req SDP\n");
+		goto error;
+	    }
+	    
+	    sdp_session = get_sdp_session(t->uas.request, 0);
+	    if (!sdp_session) {
+		    LM_ERR("Missing SDP session information from req\n");
+		    goto error;
+	    }
+	    ip = sdp_session->ip_addr;
+	    free_sdp((sdp_info_t**) (void*) &t->uas.request->body);
+	    
+	} else {
+	    LM_DBG("terminating direction\n");
+	    if ((identifier = cscf_get_asserted_identity(msg, 0)).len == 0) {
+		LM_DBG("No P-Asserted-Identity hdr found in response. Using To hdr in resp");
+		identifier = cscf_get_public_identity(msg); //get public identity from to header
+	    }
+	    
+	    //get ip from reply sdp (we use first SDP session)
+	    if (parse_sdp(msg) < 0) {
+		LM_ERR("Unable to parse req SDP\n");
+		goto error;
+	    }
+	    
+	    sdp_session = get_sdp_session(msg, 0);
+	    if (!sdp_session) {
+		    LM_ERR("Missing SDP session information from reply\n");
+		    goto error;
+	    }
+	    ip = sdp_session->ip_addr;
+	    free_sdp((sdp_info_t**) (void*) &msg->body);
+	    
+	}
+
+        int ret = create_new_callsessiondata(&callid, &ftag, &ttag, &identifier, &ip, &rx_authdata_p);
         if (!ret) {
             LM_DBG("Unable to create new media session data parcel\n");
             goto error;
         }
+	
+	//free this cscf_get_asserted_identity allocates it
+	if (must_free_asserted_identity) {
+		pkg_free(identifier.s);
+		must_free_asserted_identity = 1;
+	}
+	
+	//create new diameter auth session
         auth_session = cdpb.AAACreateClientAuthSession(1, callback_for_cdp_session, rx_authdata_p); //returns with a lock
         if (!auth_session) {
             LM_ERR("Rx: unable to create new Rx Media Session\n");
@@ -582,6 +653,12 @@ error:
         free_saved_transaction_global_data(saved_t_data); //only free global data if no AARs were sent. if one was sent we have to rely on the callback (CDP) to free
     //otherwise the callback will segfault
 
+    //free this cscf_get_asserted_identity allocates it
+    if (must_free_asserted_identity) {
+	    pkg_free(identifier.s);
+	    must_free_asserted_identity = 1;
+    }
+
      return CSCF_RETURN_ERROR;
 }
 

+ 9 - 27
modules/ims_qos/rx_aar.c

@@ -318,7 +318,7 @@ int rx_process_aaa(AAAMessage *aaa, unsigned int * rc) {
 
 /** Helper function for adding media component AVPs for each SDP stream*/
 int add_media_components(AAAMessage* aar, struct sip_msg *req,
-        struct sip_msg *rpl, enum dialog_direction direction, str *ip,
+        struct sip_msg *rpl, enum dialog_direction direction,
         uint16_t *ip_version) {
     int sdp_session_num;
     int sdp_stream_num;
@@ -359,12 +359,11 @@ int add_media_components(AAAMessage* aar, struct sip_msg *req,
             break;
         }
 
+	//we only populate ip if its not already populated
         if (direction == DLG_MOBILE_ORIGINATING) {
             *ip_version = req_sdp_session->pf;
-            *ip = req_sdp_session->ip_addr;
         } else if (direction == DLG_MOBILE_TERMINATING) {
             *ip_version = rpl_sdp_session->pf;
-            *ip = rpl_sdp_session->ip_addr;
         }
 
         sdp_stream_num = 0;
@@ -429,6 +428,12 @@ int rx_send_aar(struct sip_msg *req, struct sip_msg *res,
     str ip;
     uint16_t ip_version;
 
+    //we get ip and identifier for the auth session data 
+    rx_authsessiondata_t* p_session_data = 0;
+    p_session_data = (rx_authsessiondata_t*) auth->u.auth.generic_data;
+    identifier = p_session_data->identifier;
+    ip = p_session_data->ip;
+    
     /* find direction for AAR (orig/term) */
     //need this to add the media component details
     enum dialog_direction dlg_direction = get_dialog_direction(direction);
@@ -494,30 +499,7 @@ int rx_send_aar(struct sip_msg *req, struct sip_msg *res,
     }
 
     LM_DBG("Adding subscription id...\n");
-    //if its mo we use p_asserted_identity in request - if that not there we use from_uri
-    //if its mt we use p_asserted_identity in reply - if that not there we use to_uri
-    
-    if (dlg_direction == DLG_MOBILE_ORIGINATING) {
-	LM_DBG("originating direction\n");
-	if ((identifier = cscf_get_asserted_identity(req, 1)).len == 0) {
-	    LM_DBG("No P-Asserted-Identity hdr found in request. Using From hdr in req");
-
-	    if (!cscf_get_from_uri(req, &identifier)) {
-		    LM_ERR("Error assigning P-Asserted-Identity using From hdr in req");
-		    goto error;
-	    }
-	} else {
-	                must_free_asserted_identity = 1;
-	}
-    } else {
-	LM_DBG("terminating direction\n");
 
-	if ((identifier = cscf_get_asserted_identity(res, 0)).len == 0) {
-	    LM_DBG("No P-Asserted-Identity hdr found in response. Using To hdr in resp");
-	    identifier = cscf_get_public_identity(res); //get public identity from to header
-	}
-    }
-    
     if (strncasecmp(identifier.s,"tel:",4)==0) {
 	identifier_type = AVP_Subscription_Id_Type_E164; //
     }else{
@@ -561,7 +543,7 @@ int rx_send_aar(struct sip_msg *req, struct sip_msg *res,
      * 									*[Codec-Data]
      */
 
-    add_media_components(aar, req, res, dlg_direction, &ip, &ip_version);
+    add_media_components(aar, req, res, dlg_direction, &ip_version);
 
     LM_DBG("Adding framed ip address [%.*s]\n", ip.len, ip.s);
     /* Add Framed IP address AVP*/

+ 16 - 2
modules/ims_qos/rx_authdata.c

@@ -103,9 +103,9 @@ int create_new_regsessiondata(str* domain, str* aor, rx_authsessiondata_t** sess
 	return 1;
 }
 
-int create_new_callsessiondata(str* callid, str* ftag, str* ttag, rx_authsessiondata_t** session_data) {
+int create_new_callsessiondata(str* callid, str* ftag, str* ttag, str* identifier, str* ip, rx_authsessiondata_t** session_data) {
 
-	int len = callid->len + ftag->len + ttag->len + sizeof(rx_authsessiondata_t);
+	int len = callid->len + ftag->len + ttag->len + identifier->len + ip->len + sizeof(rx_authsessiondata_t);
 	rx_authsessiondata_t* call_session_data = shm_malloc(len);
 	if (!call_session_data){
 		LM_ERR("no more shm mem trying to create call_session_data of size %d\n", len);
@@ -138,6 +138,20 @@ int create_new_callsessiondata(str* callid, str* ftag, str* ttag, rx_authsession
                 call_session_data->ttag.len = ttag->len;
 		p += ttag->len;
 	}
+	if (identifier && identifier->len > 0 && identifier->s) {
+		LM_DBG("Copying identifier [%.*s] into call session data\n", identifier->len, identifier->s);
+		call_session_data->identifier.s = p;
+		memcpy(call_session_data->identifier.s, identifier->s, identifier->len);
+                call_session_data->identifier.len = identifier->len;
+		p += identifier->len;
+	}
+	if (ip && ip->len > 0 && ip->s) {
+		LM_DBG("Copying ip [%.*s] into call session data\n", ip->len, ip->s);
+		call_session_data->ip.s = p;
+		memcpy(call_session_data->ip.s, ip->s, ip->len);
+                call_session_data->ip.len = ip->len;
+		p += ip->len;
+	}
 	if (p != ((char*)(call_session_data) + len)) {
 		LM_ERR("buffer under/overflow\n");
 		shm_free(call_session_data);

+ 3 - 1
modules/ims_qos/rx_authdata.h

@@ -65,6 +65,8 @@ typedef struct rx_authsessiondata {
     str callid;
     str ftag;
     str ttag;
+    str identifier;
+    str ip;
     //for registration session
     int subscribed_to_signaling_path_status; // 0 not subscribed 1 is subscribed
     str domain;				//the domain the registration aor belongs to (for registration)
@@ -73,7 +75,7 @@ typedef struct rx_authsessiondata {
 } rx_authsessiondata_t;
 
 int create_new_regsessiondata(str* domain, str* aor, rx_authsessiondata_t** session_data);
-int create_new_callsessiondata(str* callid, str* ftag, str* ttag, rx_authsessiondata_t** session_data);
+int create_new_callsessiondata(str* callid, str* ftag, str* ttag, str* identifier, str *ip, rx_authsessiondata_t** session_data);
 
 #endif