Browse Source

ims_usrloc_pcscf: added a new match key for ipsec location tbl

- ipsec location table: added a new match key for ipsec location
  table. The added key is "received_port" column. It's necessary
  because after successful re-registration into the table are
  stored two contacts withe the same AOR. Before the changes only
  the AOR was contact's match key.
- ul callbacks: added a method delete_ulcb(), wich is used to delete
  the pending IPSEC tunnels for the unsuccessfuly registered contacts.
- udomain: adde a new method unreg_pending_contacts_cb(). Used to search
  and delete user callbacks for all pending contacts with default SIP
  port (5060) after successful contact registration.
- ipsec structure: added a new vars in ipsec_t - port_pc (port proxy
  client) and port_ps (port proxy server). Used to keep proxy ports
  for already created IPSEC tunnels.
Aleksandar Yosifov 6 years ago
parent
commit
59c4e08fa5

+ 101 - 0
src/modules/ims_usrloc_pcscf/udomain.c

@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2012 Smile Communications, [email protected]
  * Copyright (C) 2012 Smile Communications, [email protected]
+ * Copyright (C) 2019 Aleksandar Yosifov
  * 
  * The initial version of this code was written by Dragos Vingarzan
  * (dragos(dot)vingarzan(at)fokus(dot)fraunhofer(dot)de and the
@@ -696,6 +697,106 @@ int delete_pcontact(udomain_t* _d, /*str* _aor, str* _received_host, int _receiv
 	return 0;
 }
 
+int unreg_pending_contacts_cb(udomain_t* _d, pcontact_t* _c, int type)
+{
+	pcontact_t*		c;
+	pcontact_info_t	contact_info;
+	unsigned int	aorhash, sl, i;
+
+	contact_info.via_host = _c->via_host;
+	contact_info.via_port = SIP_PORT;
+	contact_info.via_prot = _c->via_proto;
+	contact_info.reg_state = PCONTACT_ANY;
+
+	LM_DBG("Searching for contact in P-CSCF usrloc based on VIA [%d://%.*s:%d], reg state 0x%02X\n",
+			contact_info.via_prot, contact_info.via_host.len, contact_info.via_host.s, contact_info.via_port, contact_info.reg_state);
+	
+	aorhash = get_aor_hash(_d, &contact_info.via_host, contact_info.via_port, contact_info.via_prot);
+	sl = aorhash & (_d->size - 1);
+        
+    LM_DBG("get_pcontact slot is [%d]\n", sl);
+	c = _d->table[sl].first;
+
+	for(i = 0; i < _d->table[sl].n; i++){
+		LM_DBG("comparing contact with aorhash [%u], aor [%.*s]\n", c->aorhash, c->aor.len, c->aor.s);
+		LM_DBG("contact host [%.*s:%d]\n", c->contact_host.len, c->contact_host.s, c->contact_port);
+
+		if(c->aorhash == aorhash){
+			ip_addr_t c_ip_addr;
+			ip_addr_t ci_ip_addr;
+
+			// convert 'contact->contact host' ip string to ip_addr_t
+			if (str2ipxbuf(&c->contact_host, &c_ip_addr) < 0){
+				LM_ERR("Unable to convert c->contact_host [%.*s]\n", c->contact_host.len, c->contact_host.s);
+				return 1;
+			}
+
+			// convert 'contact info->via host' ip string to ip_addr_t
+			if(str2ipxbuf(&contact_info.via_host, &ci_ip_addr) < 0){
+				LM_ERR("Unable to convert contact_info.via_host [%.*s]\n", contact_info.via_host.len, contact_info.via_host.s);
+				return 1;
+			}
+
+			// compare 'contact->contact host' and 'contact info->via host'
+			if(ip_addr_cmp(&c_ip_addr, &ci_ip_addr) && (c->contact_port == contact_info.via_port)){
+				LM_DBG("found contact with URI [%.*s]\n", c->aor.len, c->aor.s);
+
+				// finally check state being searched for
+				if((contact_info.reg_state != PCONTACT_ANY) && ((contact_info.reg_state & c->reg_state) == 0)){
+					LM_DBG("can't find contact for requested reg state [%d] - (have [%d])\n", contact_info.reg_state, c->reg_state);
+					c = c->next;
+					continue;
+				}
+
+				// check for equal ipsec parameters
+				if(c->security_temp == NULL || _c->security_temp == NULL){
+					LM_DBG("Invalid temp security\n");
+					c = c->next;
+					continue;
+				}
+
+				if(c->security_temp->type != SECURITY_IPSEC){
+					LM_DBG("Invalid temp security type\n");
+					c = c->next;
+					continue;
+				}
+
+				if(c->security_temp->data.ipsec == NULL || _c->security_temp->data.ipsec == NULL){
+					LM_DBG("Invalid ipsec\n");
+					c = c->next;
+					continue;
+				}
+
+				LM_DBG("=========== c->reg_state 0x%02X, %u-%u | %u-%u | %u-%u | %u-%u | %u-%u | %u-%u | %u-%u | %u-%u |",
+					c->reg_state,
+					c->security_temp->data.ipsec->port_pc, _c->security_temp->data.ipsec->port_pc,
+				    c->security_temp->data.ipsec->port_ps, _c->security_temp->data.ipsec->port_ps,
+				    c->security_temp->data.ipsec->port_uc, _c->security_temp->data.ipsec->port_uc,
+				    c->security_temp->data.ipsec->port_us, _c->security_temp->data.ipsec->port_us,
+				    c->security_temp->data.ipsec->spi_pc, _c->security_temp->data.ipsec->spi_pc,
+				    c->security_temp->data.ipsec->spi_ps, _c->security_temp->data.ipsec->spi_ps,
+				    c->security_temp->data.ipsec->spi_uc, _c->security_temp->data.ipsec->spi_uc,
+				    c->security_temp->data.ipsec->spi_us, _c->security_temp->data.ipsec->spi_us);
+
+				if(c->security_temp->data.ipsec->port_pc == _c->security_temp->data.ipsec->port_pc &&
+				   c->security_temp->data.ipsec->port_ps == _c->security_temp->data.ipsec->port_ps &&
+				   c->security_temp->data.ipsec->port_uc == _c->security_temp->data.ipsec->port_uc &&
+				   c->security_temp->data.ipsec->port_us == _c->security_temp->data.ipsec->port_us &&
+				   c->security_temp->data.ipsec->spi_pc == _c->security_temp->data.ipsec->spi_pc &&
+				   c->security_temp->data.ipsec->spi_ps == _c->security_temp->data.ipsec->spi_ps &&
+				   c->security_temp->data.ipsec->spi_uc == _c->security_temp->data.ipsec->spi_uc &&
+				   c->security_temp->data.ipsec->spi_us == _c->security_temp->data.ipsec->spi_us){
+					// deregister user callback only for contacts with exact sec parameters like registerd contact
+					delete_ulcb(c, type);
+				}
+			}
+		}
+		c = c->next;
+	}
+
+	return 0;
+}
+
 /*!
  * \brief Convert database values into pcontact_info
  *

+ 1 - 0
src/modules/ims_usrloc_pcscf/udomain.h

@@ -77,6 +77,7 @@ int insert_pcontact(struct udomain* _d, str* _contact, struct pcontact_info* _ci
 int get_pcontact(udomain_t* _d, pcontact_info_t* contact_info, struct pcontact** _r);
 int assert_identity(udomain_t* _d, str * _host, unsigned short _port, unsigned short _proto, str * _identity);
 int delete_pcontact(udomain_t* _d, struct pcontact* _r);
+int unreg_pending_contacts_cb(udomain_t* _d, pcontact_t* _c, int type);
 int update_security(udomain_t* _d, security_type _t, security_t* _s, struct pcontact* _c);
 int update_temp_security(udomain_t* _d, security_type _t, security_t* _s, struct pcontact* _c);
 

+ 44 - 0
src/modules/ims_usrloc_pcscf/ul_callback.c

@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2012 Smile Communications, [email protected]
  * Copyright (C) 2012 Smile Communications, [email protected]
+ * Copyright (C) 2019 Aleksandar Yosifov
  * 
  * The initial version of this code was written by Dragos Vingarzan
  * (dragos(dot)vingarzan(at)fokus(dot)fraunhofer(dot)de and the
@@ -138,6 +139,49 @@ int register_ulcb( struct pcontact *c, int types, ul_cb f, void *param )
 	return 1;
 }
 
+void delete_ulcb(struct pcontact* c, int type)
+{
+	struct ul_callback* cur;
+	struct ul_callback* prev;
+
+	if(c->cbs.first == 0 || ((c->cbs.reg_types) & type) == 0){
+		return;
+	}
+
+	// if the target is the first callback
+	cur = c->cbs.first;
+	if(cur->types & type){
+		if(cur->param){
+			if(*((unsigned short*)cur->param) == c->received_port){
+				LM_DBG("Removed ulcb from the head for contact: aor[%.*s], via port %u, received port %u, types 0x%02X\n", c->aor.len, c->aor.s, c->via_port, c->received_port, cur->types);
+				c->cbs.first = cur->next;
+				shm_free(cur);
+				return;
+			}
+		}
+	}
+
+	prev = c->cbs.first;
+	cur = c->cbs.first->next;
+	while(cur){
+		if(cur->types & type){
+			if(cur->param){
+				if(*((unsigned short*)cur->param) == c->received_port){
+					prev->next = cur->next;
+					LM_DBG("Removed ulcb for contact: aor[%.*s], via port %u, received port %u, types 0x%02X\n", c->aor.len, c->aor.s, c->via_port, c->received_port, cur->types);
+					shm_free(cur);
+					return;
+				}
+			}
+		}
+
+		prev = cur;
+		cur = cur->next;
+	}
+
+	LM_DBG("No ulcb has been deleted for contact: aor[%.*s], via port %u, received port %u\n", c->aor.len, c->aor.s, c->via_port, c->received_port);
+}
+
 /*! \brief run all transaction callbacks for an event type */
 void run_ul_callbacks( int type , struct pcontact *c)
 {

+ 1 - 0
src/modules/ims_usrloc_pcscf/ul_callback.h

@@ -81,6 +81,7 @@ int init_ulcb_list(void);
 void destroy_ulcb_list(void);
 void destroy_ul_callbacks_list(struct ul_callback* cb);
 int register_ulcb( struct pcontact *c, int types, ul_cb f, void *param);
+void delete_ulcb(struct pcontact* c, int type);
 void run_ul_callbacks( int type , struct pcontact *c);
 void run_ul_create_callbacks(struct pcontact *c);
 

+ 1 - 0
src/modules/ims_usrloc_pcscf/usrloc.c

@@ -70,6 +70,7 @@ int bind_usrloc(usrloc_api_t* api) {
 	api->unlock_udomain = unlock_udomain;
 	api->insert_pcontact = insert_pcontact;
 	api->delete_pcontact = delete_pcontact;
+    api->unreg_pending_contacts_cb = unreg_pending_contacts_cb;
 	api->get_pcontact = get_pcontact;
 	api->assert_identity = assert_identity;
 	api->update_pcontact = update_pcontact;

+ 4 - 0
src/modules/ims_usrloc_pcscf/usrloc.h

@@ -107,6 +107,8 @@ typedef struct ipsec {
     unsigned int spi_ps; /**< SPI Server to use					*/
     unsigned short port_uc; /**< Port UE Client						*/
     unsigned short port_us; /**< Port UE Server						*/
+    unsigned short port_pc; /**< Port Proxy Client		*/
+    unsigned short port_ps; /**< Port Proxy Server      */
 
     str ealg; /**< Cypher Algorithm - ESP				*/
     str r_ealg; /**< received Cypher Algorithm - ESP	*/
@@ -241,6 +243,7 @@ typedef int (*assert_identity_t)(struct udomain* _d, str * _host, unsigned short
 
 typedef int (*insert_pcontact_t)(struct udomain* _d, str* _aor, struct pcontact_info* ci, struct pcontact** _c);
 typedef int (*delete_pcontact_t)(struct udomain* _d, struct pcontact* _c);
+typedef int (*unreg_pending_contacts_cb_t)(struct udomain* _d, struct pcontact* _c, int type);
 typedef int (*update_pcontact_t)(struct udomain* _d, struct pcontact_info* ci, struct pcontact* _c);
 typedef int (*update_rx_regsession_t)(struct udomain* _d, str* session_id, struct pcontact* _c);
 
@@ -266,6 +269,7 @@ typedef struct usrloc_api {
 
     insert_pcontact_t insert_pcontact;
     delete_pcontact_t delete_pcontact;
+    unreg_pending_contacts_cb_t unreg_pending_contacts_cb;
     get_pcontact_t get_pcontact;
     assert_identity_t assert_identity;
 

+ 85 - 34
src/modules/ims_usrloc_pcscf/usrloc_db.c

@@ -3,6 +3,8 @@
  *
  *  Created on: Nov 11, 2013
  *      Author: carlos
+ * 
+ * Copyright (C) 2019 Aleksandar Yosifov
  */
 
 #include "../../lib/srdb1/db.h"
@@ -32,6 +34,8 @@ str ck_col				= str_init(CK_COL);
 str ik_col 				= str_init(IK_COL);
 str ealg_col			= str_init(EALG_COL);
 str ialg_col 			= str_init(IALG_COL);
+str port_pc_col			= str_init(PORTPC_COL);
+str port_ps_col 		= str_init(PORTPS_COL);
 str port_uc_col			= str_init(PORTUC_COL);
 str port_us_col 		= str_init(PORTUS_COL);
 str spi_pc_col 			= str_init(SPIPC_COL);
@@ -45,6 +49,8 @@ str t_ck_col			= str_init(T_CK_COL);
 str t_ik_col 			= str_init(T_IK_COL);
 str t_ealg_col			= str_init(T_EALG_COL);
 str t_ialg_col 			= str_init(T_IALG_COL);
+str t_port_pc_col		= str_init(T_PORTPC_COL);
+str t_port_ps_col 		= str_init(T_PORTPS_COL);
 str t_port_uc_col		= str_init(T_PORTUC_COL);
 str t_port_us_col 		= str_init(T_PORTUS_COL);
 str t_spi_pc_col 		= str_init(T_SPIPC_COL);
@@ -121,22 +127,27 @@ int db_update_pcontact(pcontact_t* _c)
 {
 	str impus, service_routes;
 
-	db_val_t match_values[1];
-	db_key_t match_keys[1] = { &aor_col };
-        db_op_t op[1];
+	db_val_t match_values[2];
+	db_key_t match_keys[2] = { &aor_col, &received_port_col };
+    db_op_t op[2];
 	db_key_t update_keys[8] = { &expires_col, &reg_state_col,
 								&service_routes_col, &received_col,
 								&received_port_col, &received_proto_col,
 								&rx_session_id_col, &public_ids_col };
 	db_val_t values[8];
         
-        LM_DBG("updating pcontact: %.*s\n", _c->aor.len, _c->aor.s);
+    LM_DBG("updating pcontact: aor[%.*s], received port %u\n", _c->aor.len, _c->aor.s, _c->received_port);
 
 	VAL_TYPE(match_values) = DB1_STR;
-
 	VAL_NULL(match_values) = 0;
 	VAL_STR(match_values) = _c->aor;
-        op[0]=OP_EQ;
+
+	VAL_TYPE(match_values + 1)	= DB1_INT;
+	VAL_NULL(match_values + 1)	= 0;
+	VAL_INT(match_values + 1)	= _c->received_port;
+	
+	op[0]=OP_EQ;
+	op[1]=OP_EQ;
 
 	if (use_location_pcscf_table(_c->domain) < 0) {
 		LM_ERR("Error trying to use table %.*s\n", _c->domain->len, _c->domain->s);
@@ -184,7 +195,7 @@ int db_update_pcontact(pcontact_t* _c)
 	SET_PROPER_NULL_FLAG(impus, values, 7);
 	SET_STR_VALUE(values + 7, impus);
 
-	if((ul_dbf.update(ul_dbh, match_keys, op, match_values, update_keys,values, 1, 8)) !=0){
+	if((ul_dbf.update(ul_dbh, match_keys, op, match_values, update_keys,values, 2, 8)) !=0){
 		LM_ERR("could not update database info\n");
 	    return -1;
 	}
@@ -201,22 +212,27 @@ int db_update_pcontact(pcontact_t* _c)
 
 int db_delete_pcontact(pcontact_t* _c)
 {
-	LM_DBG("Trying to delete contact: %.*s\n", _c->aor.len, _c->aor.s);
+	LM_DBG("Trying to delete contact: aor[%.*s], received port %u\n", _c->aor.len, _c->aor.s, _c->received_port);
 	db_val_t values[1];
-	db_key_t match_keys[1] = { &aor_col};
+	db_key_t match_keys[2] = { &aor_col, &received_port_col };
 
 	VAL_TYPE(values) = DB1_STR;
 	VAL_NULL(values) = 0;
 	SET_STR_VALUE(values, _c->aor);
 
+	VAL_TYPE(values + 1) = DB1_INT;
+	VAL_NULL(values + 1) = 0;
+	VAL_INT(values + 1)	 = _c->received_port;
+
 	if (use_location_pcscf_table(_c->domain) < 0) {
 		LM_ERR("Error trying to use table %.*s\n", _c->domain->len, _c->domain->s);
 		return -1;
 	}
 
-    if(ul_dbf.delete(ul_dbh, match_keys, 0, values, 1) < 0) {
-    	LM_ERR("Failed to delete database information: aor[%.*s], rx_session_id=[%.*s]\n",
+    if(ul_dbf.delete(ul_dbh, match_keys, 0, values, 2) < 0) {
+    	LM_ERR("Failed to delete database information: aor[%.*s], received port %u, rx_session_id=[%.*s]\n",
     													_c->aor.len, _c->aor.s,
+														_c->received_port,
     													_c->rx_session_id.len, _c->rx_session_id.s);
         return -1;
     }
@@ -334,20 +350,27 @@ int db_insert_pcontact(struct pcontact* _c)
 }
 
 int db_update_pcontact_security_temp(struct pcontact* _c, security_type _t, security_t* _s) {
-	db_val_t match_values[1];
-	db_key_t match_keys[1] = { &aor_col };
-        db_op_t op[1];
-	db_key_t update_keys[13] = { &t_security_type_col, &t_protocol_col,
-			&t_mode_col, &t_ck_col, &t_ik_col, &t_ealg_col, &t_ialg_col, &t_port_uc_col,
+	db_val_t match_values[2];
+	db_key_t match_keys[2] = { &aor_col, &received_port_col };
+    db_op_t op[2];
+
+	db_key_t update_keys[15] = { &t_security_type_col, &t_protocol_col,
+			&t_mode_col, &t_ck_col, &t_ik_col, &t_ealg_col, &t_ialg_col, &t_port_pc_col, &t_port_ps_col, &t_port_uc_col,
 			&t_port_us_col, &t_spi_pc_col, &t_spi_ps_col, &t_spi_uc_col, &t_spi_us_col };
-	db_val_t values[13];
+	db_val_t values[15];
 
-	LM_DBG("updating temp security for pcontact: %.*s\n", _c->aor.len, _c->aor.s);
+	LM_CRIT("updating temp security for pcontact: aor[%.*s], received port %u\n", _c->aor.len, _c->aor.s, _c->received_port);
 
 	VAL_TYPE(match_values) = DB1_STR;
 	VAL_NULL(match_values) = 0;
 	VAL_STR(match_values) = _c->aor;
-        op[0]=OP_EQ;
+
+	VAL_TYPE(match_values + 1)	= DB1_INT;
+	VAL_NULL(match_values + 1)	= 0;
+	VAL_INT(match_values + 1)	= _c->received_port;
+
+    op[0]=OP_EQ;
+	op[1]=OP_EQ;
 
 	if (use_location_pcscf_table(_c->domain) < 0) {
 		LM_ERR("Error trying to use table %.*s\n", _c->domain->len, _c->domain->s);
@@ -374,42 +397,58 @@ int db_update_pcontact_security_temp(struct pcontact* _c, security_type _t, secu
 		VAL_TYPE(values + ++i) = DB1_STR;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_STR(values + i) = ipsec?ipsec->ck:s_empty;
+
 		VAL_TYPE(values + ++i) = DB1_STR;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_STR(values + i) = ipsec?ipsec->ik:s_empty;
+
 		VAL_TYPE(values + ++i) = DB1_STR;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_STR(values + i) = ipsec?ipsec->ealg:s_empty;
+
 		VAL_TYPE(values + ++i) = DB1_STR;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_STR(values + i) = ipsec?ipsec->alg:s_empty;
+
+		VAL_TYPE(values + ++i) = DB1_INT;
+		VAL_NULL(values + i) = ipsec?0:1;
+		VAL_INT(values + i) = ipsec?ipsec->port_pc:0;
+
+		VAL_TYPE(values + ++i) = DB1_INT;
+		VAL_NULL(values + i) = ipsec?0:1;
+		VAL_INT(values + i) = ipsec?ipsec->port_ps:0;
+
 		VAL_TYPE(values + ++i) = DB1_INT;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_INT(values + i) = ipsec?ipsec->port_uc:0;
+
 		VAL_TYPE(values + ++i) = DB1_INT;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_INT(values + i) = ipsec?ipsec->port_us:0;
+
 		VAL_TYPE(values + ++i) = DB1_BIGINT;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_BIGINT(values + i) = ipsec?ipsec->spi_pc:0;
+
 		VAL_TYPE(values + ++i) = DB1_BIGINT;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_BIGINT(values + i) = ipsec?ipsec->spi_ps:0;
+
 		VAL_TYPE(values + ++i) = DB1_BIGINT;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_BIGINT(values + i) = ipsec?ipsec->spi_uc:0;
+
 		VAL_TYPE(values + ++i) = DB1_BIGINT;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_BIGINT(values + i) = ipsec?ipsec->spi_us:0;
 
-		if ((ul_dbf.update(ul_dbh, match_keys, op, match_values, update_keys,
-				values, 1, 13)) != 0) {
+		if ((ul_dbf.update(ul_dbh, match_keys, op, match_values, update_keys, values, 2, 15)) != 0) {
 			LM_ERR("could not update database info\n");
 			return -1;
 		}
 
 		if (ul_dbf.affected_rows && ul_dbf.affected_rows(ul_dbh) == 0) {
-			LM_DBG("no existing rows for an update... doing insert\n");
+			LM_CRIT("no existing rows for an update... doing insert\n");
 			if (db_insert_pcontact(_c) != 0) {
 				LM_ERR("Failed to insert a pcontact on update\n");
 			}
@@ -425,21 +464,27 @@ int db_update_pcontact_security_temp(struct pcontact* _c, security_type _t, secu
 }
 
 int db_update_pcontact_security(struct pcontact* _c, security_type _t, security_t* _s) {
-	db_val_t match_values[1];
-	db_key_t match_keys[1] = { &aor_col };
-        db_op_t op[1];
-        
-	db_key_t update_keys[13] = { &security_type_col, &protocol_col,
-			&mode_col, &ck_col, &ik_col, &ealg_col, &ialg_col, &port_uc_col,
+	db_val_t match_values[2];
+	db_key_t match_keys[2] = { &aor_col, &received_port_col };
+    db_op_t op[2];
+
+    db_key_t update_keys[15] = { &security_type_col, &protocol_col,
+			&mode_col, &ck_col, &ik_col, &ealg_col, &ialg_col, &port_pc_col, &port_ps_col, &port_uc_col,
 			&port_us_col, &spi_pc_col, &spi_ps_col, &spi_uc_col, &spi_us_col };
-	db_val_t values[13];
+	db_val_t values[15];
 
-	LM_DBG("updating security for pcontact: %.*s\n", _c->aor.len, _c->aor.s);
+	LM_DBG("updating security for pcontact: aor[%.*s], received port %u\n", _c->aor.len, _c->aor.s, _c->received_port);
 
 	VAL_TYPE(match_values) = DB1_STR;
 	VAL_NULL(match_values) = 0;
 	VAL_STR(match_values) = _c->aor;
-        op[0]=OP_EQ;
+
+	VAL_TYPE(match_values + 1)	= DB1_INT;
+	VAL_NULL(match_values + 1)	= 0;
+	VAL_INT(match_values + 1)	= _c->received_port;
+	
+	op[0]=OP_EQ;
+	op[1]=OP_EQ;
 
 	if (use_location_pcscf_table(_c->domain) < 0) {
 		LM_ERR("Error trying to use table %.*s\n", _c->domain->len, _c->domain->s);
@@ -449,7 +494,6 @@ int db_update_pcontact_security(struct pcontact* _c, security_type _t, security_
 	VAL_TYPE(values) = DB1_INT;
 	VAL_TIME(values) = _s?_s->type:0;
 	VAL_NULL(values) = 0;
-        
 
 	switch (_t) {
 	case SECURITY_IPSEC: {
@@ -480,6 +524,14 @@ int db_update_pcontact_security(struct pcontact* _c, security_type _t, security_
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_STR(values + i) = ipsec?ipsec->alg:s_empty;
 
+		VAL_TYPE(values + ++i) = DB1_INT;
+		VAL_NULL(values + i) = ipsec?0:1;
+		VAL_INT(values + i) = ipsec?ipsec->port_pc:0;
+
+		VAL_TYPE(values + ++i) = DB1_INT;
+		VAL_NULL(values + i) = ipsec?0:1;
+		VAL_INT(values + i) = ipsec?ipsec->port_ps:0;
+
 		VAL_TYPE(values + ++i) = DB1_INT;
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_INT(values + i) = ipsec?ipsec->port_uc:0;
@@ -504,8 +556,7 @@ int db_update_pcontact_security(struct pcontact* _c, security_type _t, security_
 		VAL_NULL(values + i) = ipsec?0:1;
 		VAL_BIGINT(values + i) = ipsec?ipsec->spi_us:0;
 
-		if ((ul_dbf.update(ul_dbh, match_keys, op, match_values, update_keys,
-				values, 1, 13)) != 0) {
+		if ((ul_dbf.update(ul_dbh, match_keys, op, match_values, update_keys, values, 2, 15)) != 0) {
 			LM_ERR("could not update database info\n");
 			return -1;
 		}

+ 4 - 0
src/modules/ims_usrloc_pcscf/usrloc_db.h

@@ -77,6 +77,8 @@ typedef enum location_pcscf_fields_idx {
 #define IK_COL				"ik"
 #define EALG_COL			"ealg"
 #define IALG_COL			"ialg"
+#define PORTPC_COL			"port_pc"
+#define PORTPS_COL			"port_ps"
 #define PORTUC_COL			"port_uc"
 #define PORTUS_COL			"port_us"
 #define SPIPC_COL			"spi_pc"
@@ -90,6 +92,8 @@ typedef enum location_pcscf_fields_idx {
 #define T_IK_COL			"t_ik"
 #define T_EALG_COL			"t_ealg"
 #define T_IALG_COL			"t_ialg"
+#define T_PORTPC_COL		"t_port_pc"
+#define T_PORTPS_COL		"t_port_ps"
 #define T_PORTUC_COL		"t_port_uc"
 #define T_PORTUS_COL		"t_port_us"
 #define T_SPIPC_COL			"t_spi_pc"