From ab3d42c47d52b1b7b315272c00daf121d9f8fc92 Mon Sep 17 00:00:00 2001 From: Dragos Vingarzan Date: Wed, 20 Jul 2016 18:31:01 +0200 Subject: [PATCH] ims_qos: create a proper flow description for the SIP signaling - before there was just an empty one in the AAR - re-using the function typically used for the RTP media - fixing then that function to not just hard-code protocol 17 (UDP) for everything - now supporting also 6 (TCP) and IP (IP has no protocol number, we use just the magic word "ip" (see RFC 3588 IPFilterRule for more details) - adding the IP of the P-CSCF as a parameter to the module, as this is required in the flow (UE IP <-> P-CSCF IP) - also some inline/static fixes to function for avoiding warnings on gcc >=5 --- modules/ims_qos/mod.c | 4 ++++ modules/ims_qos/rx_aar.c | 32 ++++++++++++++++++++++++++- modules/ims_qos/rx_avp.c | 47 ++++++++++++++++++++++++---------------- modules/ims_qos/rx_avp.h | 12 +++++----- 4 files changed, 69 insertions(+), 26 deletions(-) diff --git a/modules/ims_qos/mod.c b/modules/ims_qos/mod.c index 6cf9ae3fac8..cca1ea68fe2 100644 --- a/modules/ims_qos/mod.c +++ b/modules/ims_qos/mod.c @@ -135,6 +135,9 @@ str rx_dest_realm = str_init("ims.smilecoms.com"); /* Only used if we want to force the Rx peer usually this is configured at a stack level and the first request uses realm routing */ str rx_forced_peer = str_init(""); +/* P-CSCF IP address to generate the flows for the UE<->PCSCF signaling path */ +str rx_pcscf_ip = str_init("192.168.1.45"); + /* commands wrappers and fixups */ static int w_rx_aar(struct sip_msg *msg, char *route, char* dir, char *id, int id_type); static int w_rx_aar_register(struct sip_msg *msg, char *route, char* str1, char *bar); @@ -182,6 +185,7 @@ static cmd_export_t cmds[] = { static param_export_t params[] = { { "rx_dest_realm", PARAM_STR, &rx_dest_realm}, + { "rx_pcscf_ip", PARAM_STR, &rx_pcscf_ip}, { "rx_forced_peer", PARAM_STR, &rx_forced_peer}, { "rx_auth_expiry", INT_PARAM, &rx_auth_expiry}, { "cdp_event_latency", INT_PARAM, &cdp_event_latency}, /*flag: report slow processing of CDP callback events or not */ diff --git a/modules/ims_qos/rx_aar.c b/modules/ims_qos/rx_aar.c index f90e7f5bf3a..5a4967d9ed1 100644 --- a/modules/ims_qos/rx_aar.c +++ b/modules/ims_qos/rx_aar.c @@ -77,6 +77,8 @@ extern struct ims_qos_counters_h ims_qos_cnts_h; extern int authorize_video_flow; +extern str rx_pcscf_ip; + str IMS_Serv_AVP_val = {"IMS Services", 12}; str IMS_Em_Serv_AVP_val = {"Emergency IMS Call", 18}; str IMS_Reg_AVP_val = {"IMS Registration", 16}; @@ -897,6 +899,7 @@ int rx_send_aar_register(struct sip_msg *msg, AAASession* auth, saved_transactio AAA_AVP* avp = 0; char x[4]; str identifier; + str media; str ip; uint16_t ip_version; @@ -940,8 +943,35 @@ int rx_send_aar_register(struct sip_msg *msg, AAASession* auth, saved_transactio int identifier_type = AVP_Subscription_Id_Type_SIP_URI; //we only do IMPU now rx_add_subscription_id_avp(aar, identifier, identifier_type); + /* Create flow description for AF-Signaling */ + //add this to auth session data + media.s = "control"; + media.len = strlen("control"); + str raw_stream; + raw_stream.s = 0; + raw_stream.len = 0; + + char c_port_from[5]; + str port_from; + port_from.len = sprintf(c_port_from, "%u", saved_t_data->via_port); + port_from.s = c_port_from; + + char c_port_to[5]; + str port_to; + port_to.len = sprintf(c_port_to, "%u", saved_t_data->recv_port); + port_to.s = c_port_to; + + str protocol; + protocol.s = "IP"; + protocol.len = strlen("IP"); + /* Add media component description avp for register*/ - rx_add_media_component_description_avp_register(aar); + rx_add_media_component_description_avp(aar, 1, + &media, &saved_t_data->via_host, + &port_from, &rx_pcscf_ip, + &port_to, &protocol, + &raw_stream, + &raw_stream, DLG_MOBILE_REGISTER); /* Add specific action AVP's */ rx_add_specific_action_avp(aar, 1); // CHARGING_CORRELATION_EXCHANGE diff --git a/modules/ims_qos/rx_avp.c b/modules/ims_qos/rx_avp.c index d8f0440afd9..65fc3a2cf70 100644 --- a/modules/ims_qos/rx_avp.c +++ b/modules/ims_qos/rx_avp.c @@ -229,7 +229,7 @@ int rx_add_framed_ip_avp(AAA_AVP_LIST * list, str ip, uint16_t version) * @param acct_id - the accounting application id * @returns 1 on success or 0 on error */ -inline int rx_add_vendor_specific_appid_avp(AAAMessage *msg, unsigned int vendor_id, +inline static int rx_add_vendor_specific_appid_avp(AAAMessage *msg, unsigned int vendor_id, unsigned int auth_id, unsigned int acct_id) { AAA_AVP_LIST list; @@ -363,7 +363,7 @@ int rx_add_subscription_id_avp(AAAMessage *msg, str identifier, int identifier_t __FUNCTION__); } -inline unsigned int sdp_b_value(str * payload, char * subtype) +inline static unsigned int sdp_b_value(str * payload, char * subtype) { char * line; unsigned int i; @@ -634,14 +634,14 @@ static str permit_in = {"permit in ", 10}; static str from_s = {" from ", 6}; static str to_s = {" to ", 4}; //removed final %s - this is options which Rx 29.214 says will not be used for flow-description AVP -static char * permit_out_with_ports = "permit out %i from %.*s %u to %.*s %u"; -static char * permit_out_with_any_as_dst = "permit out %i from %.*s %u to any"; -//static char * permit_out_with_any_as_src = "permit out %i from any to %.*s %u"; -//static char * permit_out_with_ports = "permit out %i from %.*s %u to %.*s %u %s"; -static char * permit_in_with_ports = "permit in %i from %.*s %u to %.*s %u"; -static char * permit_in_with_any_as_src = "permit in %i from any to %.*s %u"; -//static char * permit_in_with_any_as_dst = "permit in %i from %.*s %u to any"; -//static char * permit_in_with_ports = "permit in %i from %.*s %u to %.*s %u %s"; +static char * permit_out_with_ports = "permit out %s from %.*s %u to %.*s %u"; +static char * permit_out_with_any_as_dst = "permit out %s from %.*s %u to any"; +//static char * permit_out_with_any_as_src = "permit out %s from any to %.*s %u"; +//static char * permit_out_with_ports = "permit out %s from %.*s %u to %.*s %u %s"; +static char * permit_in_with_ports = "permit in %s from %.*s %u to %.*s %u"; +static char * permit_in_with_any_as_src = "permit in %s from any to %.*s %u"; +//static char * permit_in_with_any_as_dst = "permit in %s from %.*s %u to any"; +//static char * permit_in_with_ports = "permit in %s from %.*s %u to %.*s %u %s"; static unsigned int flowdata_buflen = 0; static str flowdata_buf = {0, 0}; @@ -684,9 +684,18 @@ AAA_AVP *rx_create_media_subcomponent_avp(int number, char* proto, list.tail = 0; list.head = 0; char x[4]; - int proto_int = 0, proto_len = 0; - - proto_int = 17; + char *proto_nr = 0; + if (strcasecmp(proto,"IP") == 0) { + proto_nr = "ip"; + } else if (strcasecmp(proto,"UDP") == 0) { + proto_nr = "17"; + } else if (strcasecmp(proto,"TCP") == 0) { + proto_nr = "6"; + } else { + LOG(L_ERR, "Not yet implemented for protocol %s\n", proto); + return 0; + } + int proto_len = strlen(proto_nr); int intportA = atoi(portA->s); int intportB = atoi(portB->s); @@ -749,14 +758,14 @@ AAA_AVP *rx_create_media_subcomponent_avp(int number, char* proto, /*IMS Flow descriptions*/ /*first flow is the receive flow*/ if (!useAnyForIpA && !useAnyForIpB) { - flowdata_buf.len = snprintf(flowdata_buf.s, len, permit_out_with_ports, proto_int, + flowdata_buf.len = snprintf(flowdata_buf.s, len, permit_out_with_ports, proto_nr, ipA->len, ipA->s, intportA, ipB->len, ipB->s, intportB); } else if (useAnyForIpA) { - flowdata_buf.len = snprintf(flowdata_buf.s, len, permit_out_with_any_as_dst, proto_int, + flowdata_buf.len = snprintf(flowdata_buf.s, len, permit_out_with_any_as_dst, proto_nr, ipB->len, ipB->s, intportB); } else if (useAnyForIpB) { - flowdata_buf.len = snprintf(flowdata_buf.s, len, permit_out_with_any_as_dst, proto_int, + flowdata_buf.len = snprintf(flowdata_buf.s, len, permit_out_with_any_as_dst, proto_nr, ipA->len, ipA->s, intportA); } @@ -783,14 +792,14 @@ AAA_AVP *rx_create_media_subcomponent_avp(int number, char* proto, } if (!useAnyForIpA && !useAnyForIpB) { - flowdata_buf.len = snprintf(flowdata_buf.s, len2, permit_in_with_ports, proto_int, + flowdata_buf.len = snprintf(flowdata_buf.s, len2, permit_in_with_ports, proto_nr, ipB->len, ipB->s, intportB, ipA->len, ipA->s, intportA); } else if (useAnyForIpA) { - flowdata_buf.len = snprintf(flowdata_buf.s, len2, permit_in_with_any_as_src, proto_int, + flowdata_buf.len = snprintf(flowdata_buf.s, len2, permit_in_with_any_as_src, proto_nr, ipB->len, ipB->s, intportB); } else if (useAnyForIpB) { - flowdata_buf.len = snprintf(flowdata_buf.s, len2, permit_in_with_any_as_src, proto_int, + flowdata_buf.len = snprintf(flowdata_buf.s, len2, permit_in_with_any_as_src, proto_nr, ipA->len, ipA->s, intportA); } diff --git a/modules/ims_qos/rx_avp.h b/modules/ims_qos/rx_avp.h index 894a3fd9fc7..8342aab4a7c 100644 --- a/modules/ims_qos/rx_avp.h +++ b/modules/ims_qos/rx_avp.h @@ -76,13 +76,13 @@ int rx_add_avp(AAAMessage *m, char *d, int len, int avp_code, int rx_add_vendor_specific_application_id_group(AAAMessage *msg, unsigned int vendorid, unsigned int auth_app_id); int rx_add_destination_realm_avp(AAAMessage *msg, str data); -inline int rx_add_subscription_id_avp(AAAMessage *msg, str identifier, int identifier_type); -inline int rx_add_auth_application_id_avp(AAAMessage *msg, unsigned int data); +int rx_add_subscription_id_avp(AAAMessage *msg, str identifier, int identifier_type); +int rx_add_auth_application_id_avp(AAAMessage *msg, unsigned int data); -inline int rx_add_media_component_description_avp(AAAMessage *msg, int number, str *media_description, str *ipA, str *portA, str *ipB, str *portB, str *transport, +int rx_add_media_component_description_avp(AAAMessage *msg, int number, str *media_description, str *ipA, str *portA, str *ipB, str *portB, str *transport, str *raw_payload, str *rpl_raw_payload, enum dialog_direction dlg_direction); -inline int rx_add_media_component_description_avp_register(AAAMessage *msg); +int rx_add_media_component_description_avp_register(AAAMessage *msg); AAA_AVP *rx_create_media_subcomponent_avp(int number, char *proto, str *ipA, str *portA, str *ipB, str *portB); @@ -90,9 +90,9 @@ AAA_AVP *rx_create_media_subcomponent_avp_register(); AAA_AVP* rx_create_codec_data_avp(str *raw_sdp_stream, int number, int direction); -inline int rx_get_result_code(AAAMessage *msg, unsigned int *data); +int rx_get_result_code(AAAMessage *msg, unsigned int *data); unsigned int rx_get_abort_cause(AAAMessage *msg); -inline int rx_add_specific_action_avp(AAAMessage *msg, unsigned int data); +int rx_add_specific_action_avp(AAAMessage *msg, unsigned int data); #endif /*__PCC_AVP_H*/