Changes in / [949:ad5c976e0dc7:950:51c15f98a965] in freeDiameter
- Files:
-
- 1 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
INSTALL.FreeBSD
r707 r921 9 9 10 10 Then the cmake command had to look like: 11 cmake -DFLEX_EXECUTABLE:FILEPATH=/usr/local/bin/flex ...11 cmake -DFLEX_EXECUTABLE:FILEPATH=/usr/local/bin/flex -DSCTP_USE_MAPPED_ADDRESSES:BOOL=ON ... 12 12 13 13 … … 46 46 47 47 7) Run cmake for freeDiameter (add other flags as you see fit, see INSTALL for more details) 48 # /usr/local/bin/cmake -DFLEX_EXECUTABLE:FILEPATH=/usr/local/bin/flex ../freeDiameter48 # /usr/local/bin/cmake -DFLEX_EXECUTABLE:FILEPATH=/usr/local/bin/flex -DSCTP_USE_MAPPED_ADDRESSES:BOOL=ON ../freeDiameter 49 49 50 50 8) Compile, optionnaly test -
extensions/app_radgw/rgwx_auth.c
r740 r924 458 458 if (si_len) { 459 459 /* We already have the Session-Id, just use it */ 460 CHECK_FCT( fd_sess_fromsid ( si, si_len, session, NULL) );460 CHECK_FCT( fd_sess_fromsid_msg ( si, si_len, session, NULL) ); 461 461 } else { 462 462 /* Create a new Session-Id string */ … … 496 496 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 497 497 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 498 CHECK_FCT( fd_msg_sess_set( *diam_fw, *session) ); 498 499 } 499 500 -
extensions/app_radgw/rgwx_sip.c
r816 r924 480 480 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 481 481 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 482 CHECK_FCT( fd_msg_sess_set( *diam_fw, *session) ); 482 483 483 484 /* -
extensions/app_sip/registrationtermination.c
r706 r924 148 148 { 149 149 #define APP_SIP_SID_OPT "app_sip" 150 CHECK_FCT( fd_sess_new( &sess, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, (os0_t)APP_SIP_SID_OPT, CONSTSTRLEN(APP_SIP_SID_OPT) )); 151 os0_t sid; 152 size_t sidlen; 153 CHECK_FCT( fd_sess_getsid ( sess, &sid, &sidlen )); 154 CHECK_FCT( fd_msg_avp_new ( sip_dict.Session_Id, 0, &avp )); 155 value.os.data = sid; 156 value.os.len = sidlen; 157 CHECK_FCT( fd_msg_avp_setvalue( avp, &value )); 158 CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_FIRST_CHILD, avp )); 150 CHECK_FCT( fd_msg_new_session( message, (os0_t)APP_SIP_SID_OPT, CONSTSTRLEN(APP_SIP_SID_OPT) ) ); 159 151 } 160 152 -
extensions/test_app/ta_bench.c
r879 r924 122 122 union avp_value val; 123 123 struct ta_mess_info * mi = NULL; 124 struct session *sess = NULL;125 124 126 125 TRACE_DEBUG(FULL, "Creating a new message for sending."); … … 131 130 /* Create a new session */ 132 131 #define TEST_APP_SID_OPT "app_testb" 133 CHECK_FCT_DO( fd_ sess_new( &sess, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, (os0_t)TEST_APP_SID_OPT, CONSTSTRLEN(TEST_APP_SID_OPT) ), goto out );132 CHECK_FCT_DO( fd_msg_new_session( req, (os0_t)TEST_APP_SID_OPT, CONSTSTRLEN(TEST_APP_SID_OPT) ), goto out ); 134 133 135 134 /* Create the random value to store with the session */ … … 143 142 144 143 /* Now set all AVPs values */ 145 146 /* Session-Id */147 {148 os0_t sid;149 size_t sidlen;150 CHECK_FCT_DO( fd_sess_getsid ( sess, &sid, &sidlen ), goto out );151 CHECK_FCT_DO( fd_msg_avp_new ( ta_sess_id, 0, &avp ), goto out );152 val.os.data = sid;153 val.os.len = sidlen;154 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );155 CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_FIRST_CHILD, avp ), goto out );156 157 }158 144 159 145 /* Set the Destination-Realm AVP */ -
extensions/test_app/ta_cli.c
r740 r924 151 151 /* Create a new session */ 152 152 #define TEST_APP_SID_OPT "app_test" 153 CHECK_FCT_DO( fd_sess_new( &sess, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, (os0_t)TEST_APP_SID_OPT, CONSTSTRLEN(TEST_APP_SID_OPT) ), goto out ); 153 CHECK_FCT_DO( fd_msg_new_session( req, (os0_t)TEST_APP_SID_OPT, CONSTSTRLEN(TEST_APP_SID_OPT) ), goto out ); 154 CHECK_FCT_DO( fd_msg_sess_get(fd_g_config->cnf_dict, req, &sess, NULL), goto out ); 154 155 155 156 /* Create the random value to store with the session */ … … 164 165 /* Now set all AVPs values */ 165 166 166 /* Session-Id */167 {168 os0_t sid;169 size_t sidlen;170 CHECK_FCT_DO( fd_sess_getsid ( sess, &sid, &sidlen ), goto out );171 CHECK_FCT_DO( fd_msg_avp_new ( ta_sess_id, 0, &avp ), goto out );172 val.os.data = sid;173 val.os.len = sidlen;174 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), goto out );175 CHECK_FCT_DO( fd_msg_avp_add( req, MSG_BRW_FIRST_CHILD, avp ), goto out );176 177 }178 179 167 /* Set the Destination-Realm AVP */ 180 168 { -
extensions/test_sip/locationinfo.c
r706 r924 42 42 struct msg * message=NULL; 43 43 struct avp *avp=NULL; 44 struct session *sess=NULL;45 44 union avp_value value; 46 45 … … 62 61 // Create a new session 63 62 { 64 CHECK_FCT( fd_sess_new( &sess, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, (os0_t)"appsip", 6 )); 65 os0_t sid; 66 size_t sidlen; 67 CHECK_FCT( fd_sess_getsid ( sess, &sid, &sidlen )); 68 CHECK_FCT( fd_msg_avp_new ( sip_dict.Session_Id, 0, &avp )); 69 value.os.data = sid; 70 value.os.len = sidlen; 71 CHECK_FCT( fd_msg_avp_setvalue( avp, &value )); 72 CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_FIRST_CHILD, avp )); 63 CHECK_FCT( fd_msg_new_session( message, (os0_t)"appsip", CONSTSTRLEN("appsip") ) ); 73 64 } 74 65 -
extensions/test_sip/locationinfosl.c
r706 r924 42 42 struct msg * message=NULL; 43 43 struct avp *avp=NULL; 44 struct session *sess=NULL;45 44 union avp_value value; 46 45 … … 62 61 // Create a new session 63 62 { 64 CHECK_FCT( fd_sess_new( &sess, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, (os0_t)"appsip", 6 )); 65 os0_t sid; 66 size_t sidlen; 67 CHECK_FCT( fd_sess_getsid ( sess, &sid, &sidlen )); 68 CHECK_FCT( fd_msg_avp_new ( sip_dict.Session_Id, 0, &avp )); 69 value.os.data = sid; 70 value.os.len = sidlen; 71 CHECK_FCT( fd_msg_avp_setvalue( avp, &value )); 72 CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_FIRST_CHILD, avp )); 63 CHECK_FCT( fd_msg_new_session( message, (os0_t)"appsip", CONSTSTRLEN("appsip") ) ); 73 64 } 74 65 -
extensions/test_sip/serverassignment.c
r706 r924 42 42 struct msg * message=NULL; 43 43 struct avp *avp=NULL; 44 struct session *sess=NULL;45 44 union avp_value value; 46 45 … … 71 70 // Create a new session 72 71 { 73 CHECK_FCT( fd_sess_new( &sess, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, (os0_t)"appsip", 6 )); 74 os0_t sid; 75 size_t sidlen; 76 CHECK_FCT( fd_sess_getsid ( sess, &sid, &sidlen )); 77 CHECK_FCT( fd_msg_avp_new ( sip_dict.Session_Id, 0, &avp )); 78 value.os.data = sid; 79 value.os.len = sidlen; 80 CHECK_FCT( fd_msg_avp_setvalue( avp, &value )); 81 CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_FIRST_CHILD, avp )); 72 CHECK_FCT( fd_msg_new_session( message, (os0_t)"appsip", CONSTSTRLEN("appsip") ) ); 82 73 } 83 74 -
extensions/test_sip/userauthorization.c
r706 r924 42 42 struct msg * message=NULL; 43 43 struct avp *avp=NULL; 44 struct session *sess=NULL;45 44 union avp_value value; 46 45 … … 67 66 // Create a new session 68 67 { 69 CHECK_FCT( fd_sess_new( &sess, fd_g_config->cnf_diamid, fd_g_config->cnf_diamid_len, (os0_t)"appsip", 6 )); 70 os0_t sid; 71 size_t sidlen; 72 CHECK_FCT( fd_sess_getsid ( sess, &sid, &sidlen )); 73 CHECK_FCT( fd_msg_avp_new ( sip_dict.Session_Id, 0, &avp )); 74 value.os.data = sid; 75 value.os.len = sidlen; 76 CHECK_FCT( fd_msg_avp_setvalue( avp, &value )); 77 CHECK_FCT( fd_msg_avp_add( message, MSG_BRW_FIRST_CHILD, avp )); 68 CHECK_FCT( fd_msg_new_session( message, (os0_t)"appsip", CONSTSTRLEN("appsip") ) ); 78 69 } 79 70 -
include/freeDiameter/libfdproto.h
r946 r950 1158 1158 }; 1159 1159 1160 /**** 1161 Callbacks defined in libfdproto/dictionary_functions.c file -- see that file for usage. 1162 */ 1163 1164 /* Convert an Address type AVP into a struct sockaddr_storage */ 1165 int fd_dictfct_Address_encode(void * data, union avp_value * avp_value); 1166 int fd_dictfct_Address_interpret(union avp_value * avp_value, void * interpreted); 1167 char * fd_dictfct_Address_dump(union avp_value * avp_value); 1168 1169 /* Display the content of an AVP of type UTF8String in the log file */ 1170 char * fd_dictfct_UTF8String_dump(union avp_value * avp_value); 1171 1172 /* For Time AVPs, map with time_t value directly */ 1173 int fd_dictfct_Time_encode(void * data, union avp_value * avp_value); 1174 int fd_dictfct_Time_interpret(union avp_value * avp_value, void * interpreted); 1175 char * fd_dictfct_Time_dump(union avp_value * avp_value); 1176 1177 1178 1179 /****/ 1160 1180 1161 1181 /*** … … 1188 1208 1189 1209 */ 1190 1210 1191 1211 /* 1192 1212 *************************************************************************** … … 1790 1810 * 1791 1811 * RETURN VALUE: 1792 * 0 : The session is created .1793 * EINVAL : A parameter is invalid. 1794 * EALREADY : A session with the same name already exists (returned in *session) 1812 * 0 : The session is created, the initial msg refcount is 1. 1813 * EINVAL : A parameter is invalid. 1814 * EALREADY : A session with the same name already exists (returned in *session), the msg refcount is increased. 1795 1815 * ENOMEM : Not enough memory to complete the operation 1796 1816 */ … … 2479 2499 int fd_msg_sess_get(struct dictionary * dict, struct msg * msg, struct session ** session, int * isnew); 2480 2500 2501 /* This one is used by the libfdcore, you should use fd_msg_new_session rather than fd_sess_new, when possible */ 2502 int fd_msg_sess_set(struct msg * msg, struct session * session); 2503 2504 2481 2505 /***************************************/ 2482 2506 /* Manage AVP values */ -
libfdcore/dict_base_proto.c
r838 r922 45 45 struct dictionary * fd_g_dict = NULL; 46 46 47 /* The functions to encode and interpret the derived types defined in the base protocol */48 49 /* Address AVP <-> struct sockaddr_storage */50 static int Address_encode(void * data, union avp_value * avp_value)51 {52 sSS * ss = (sSS *) data;53 uint16_t AddressType = 0;54 size_t size = 0;55 unsigned char * buf = NULL;56 57 TRACE_ENTRY("%p %p", data, avp_value);58 CHECK_PARAMS( data && avp_value );59 60 switch (ss->ss_family) {61 case AF_INET:62 {63 /* We are encoding an IP address */64 sSA4 * sin = (sSA4 *)ss;65 66 AddressType = 1;/* see http://www.iana.org/assignments/address-family-numbers/ */67 size = 6; /* 2 for AddressType + 4 for data */68 69 CHECK_MALLOC( buf = malloc(size) );70 71 /* may not work because of alignment: *(uint32_t *)(buf+2) = htonl(sin->sin_addr.s_addr); */72 memcpy(buf + 2, &sin->sin_addr.s_addr, 4);73 }74 break;75 76 case AF_INET6:77 {78 /* We are encoding an IPv6 address */79 sSA6 * sin6 = (sSA6 *)ss;80 81 AddressType = 2;/* see http://www.iana.org/assignments/address-family-numbers/ */82 size = 18; /* 2 for AddressType + 16 for data */83 84 CHECK_MALLOC( buf = malloc(size) );85 86 /* The order is already good here */87 memcpy(buf + 2, &sin6->sin6_addr.s6_addr, 16);88 }89 break;90 91 default:92 CHECK_PARAMS( AddressType = 0 );93 }94 95 *(uint16_t *)buf = htons(AddressType);96 97 avp_value->os.len = size;98 avp_value->os.data = buf;99 100 return 0;101 }102 103 static int Address_interpret(union avp_value * avp_value, void * interpreted)104 {105 uint16_t AddressType = 0;106 unsigned char * buf;107 108 TRACE_ENTRY("%p %p", avp_value, interpreted);109 110 CHECK_PARAMS( avp_value && interpreted && (avp_value->os.len >= 2) );111 112 AddressType = ntohs(*(uint16_t *)avp_value->os.data);113 buf = &avp_value->os.data[2];114 115 switch (AddressType) {116 case 1 /* IP */:117 {118 sSA4 * sin = (sSA4 *)interpreted;119 120 CHECK_PARAMS( avp_value->os.len == 6 );121 122 sin->sin_family = AF_INET;123 /* sin->sin_addr.s_addr = ntohl( * (uint32_t *) buf); -- may not work because of bad alignment */124 memcpy(&sin->sin_addr.s_addr, buf, 4);125 }126 break;127 128 case 2 /* IP6 */:129 {130 sSA6 * sin6 = (sSA6 *)interpreted;131 132 CHECK_PARAMS( avp_value->os.len == 18 );133 134 sin6->sin6_family = AF_INET6;135 memcpy(&sin6->sin6_addr.s6_addr, buf, 16);136 }137 break;138 139 default:140 CHECK_PARAMS( AddressType = 0 );141 }142 143 return 0;144 }145 146 /* Dump the content of an Address AVP */147 static char * Address_dump(union avp_value * avp_value)148 {149 char * ret;150 #define STR_LEN 1024151 union {152 sSA sa;153 sSS ss;154 sSA4 sin;155 sSA6 sin6;156 } s;157 uint16_t fam;158 159 memset(&s, 0, sizeof(s));160 161 CHECK_MALLOC_DO( ret = malloc(STR_LEN), return NULL );162 163 /* The first two octets represent the address family, http://www.iana.org/assignments/address-family-numbers/ */164 if (avp_value->os.len < 2) {165 snprintf(ret, STR_LEN, "[invalid length: %zd]", avp_value->os.len);166 return ret;167 }168 169 /* Following octets are the address in network byte order already */170 fam = avp_value->os.data[0] << 8 | avp_value->os.data[1];171 switch (fam) {172 case 1:173 /* IP */174 s.sa.sa_family = AF_INET;175 if (avp_value->os.len != 6) {176 snprintf(ret, STR_LEN, "[invalid IP length: %zd]", avp_value->os.len);177 return ret;178 }179 memcpy(&s.sin.sin_addr.s_addr, avp_value->os.data + 2, 4);180 break;181 case 2:182 /* IP6 */183 s.sa.sa_family = AF_INET6;184 if (avp_value->os.len != 18) {185 snprintf(ret, STR_LEN, "[invalid IP6 length: %zd]", avp_value->os.len);186 return ret;187 }188 memcpy(&s.sin6.sin6_addr.s6_addr, avp_value->os.data + 2, 16);189 break;190 default:191 snprintf(ret, STR_LEN, "[unsupported family: 0x%hx]", fam);192 return ret;193 }194 195 {196 int rc = getnameinfo(&s.sa, sSAlen(&s.sa), ret, STR_LEN, NULL, 0, NI_NUMERICHOST);197 if (rc)198 snprintf(ret, STR_LEN, "%s", (char *)gai_strerror(rc));199 }200 201 return ret;202 }203 204 static char * UTF8String_dump(union avp_value * avp_value)205 {206 return strndup((char *)avp_value->os.data, 42); /* avoid very long strings */207 }208 209 210 47 211 48 … … 295 132 the content and format of the remaining octets. 296 133 */ 297 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "Address" , Address_interpret , Address_encode,Address_dump };134 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "Address" , fd_dictfct_Address_interpret , fd_dictfct_Address_encode, fd_dictfct_Address_dump }; 298 135 CHECK_dict_new( DICT_TYPE, &data , NULL, NULL); 299 136 } … … 314 151 This procedure MUST be supported by all DIAMETER nodes. 315 152 */ 316 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "Time" , NULL , NULL , NULL};153 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "Time" , fd_dictfct_Time_interpret , fd_dictfct_Time_encode, fd_dictfct_Time_dump }; 317 154 CHECK_dict_new( DICT_TYPE, &data , NULL, NULL); 318 155 } … … 352 189 octets, not characters. 353 190 */ 354 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "UTF8String" , NULL , NULL , UTF8String_dump };191 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "UTF8String" , NULL , NULL , fd_dictfct_UTF8String_dump }; 355 192 CHECK_dict_new( DICT_TYPE, &data , NULL, NULL); 356 193 } … … 381 218 Domain Name (IDNs). 382 219 */ 383 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "DiameterIdentity" , NULL , NULL , UTF8String_dump };220 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "DiameterIdentity" , NULL , NULL , fd_dictfct_UTF8String_dump }; 384 221 CHECK_dict_new( DICT_TYPE, &data , NULL, NULL); 385 222 } … … 436 273 aaa://host.example.com:1813;transport=udp;protocol=radius 437 274 */ 438 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "DiameterURI" , NULL , NULL , UTF8String_dump };275 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "DiameterURI" , NULL , NULL , fd_dictfct_UTF8String_dump }; 439 276 CHECK_dict_new( DICT_TYPE, &data , NULL, NULL); 440 277 } … … 498 335 infrastructure. 499 336 */ 500 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "IPFilterRule" , NULL , NULL , UTF8String_dump };337 struct dict_type_data data = { AVP_TYPE_OCTETSTRING, "IPFilterRule" , NULL , NULL , fd_dictfct_UTF8String_dump }; 501 338 CHECK_dict_new( DICT_TYPE, &data , NULL, NULL); 502 339 } -
libfdcore/fdd.l
r944 r950 52 52 yylloc->first_column = yylloc->last_column + 1; \ 53 53 yylloc->last_column = yylloc->first_column + yyleng - 1; \ 54 TRACE_DEBUG_ERROR("(%d:%d-%d:%d) matched rule %d, length=%d, txt='%s'\n", \ 54 TRACE_DEBUG_ERROR( \ 55 "(%d:%d-%d:%d) matched rule %d, length=%d, txt='%s'\n", \ 55 56 yylloc->first_line, yylloc->first_column, \ 56 57 yylloc->last_line, yylloc->last_column, \ … … 145 146 <*>[[:alnum:]]+ | /* This rule is only useful to print a complete token in error messages */ 146 147 /* Unrecognized character */ 147 <*>. { 148 <*>. { 148 149 TRACE_DEBUG_ERROR("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext); 149 150 return LEX_ERROR; -
libfdcore/fdd.y
r944 r950 328 328 if (fd == NULL) { 329 329 int ret = errno; 330 TRACE_DEBUG (INFO,"Unable to open extension file %s for reading: %s\n", fname, strerror(ret));330 TRACE_DEBUG_ERROR("Unable to open extension file %s for reading: %s\n", fname, strerror(ret)); 331 331 yyerror (&yylloc, conf, "Error adding extension"); 332 332 YYERROR; … … 502 502 if (fd == NULL) { 503 503 int ret = errno; 504 TRACE_DEBUG (INFO,"Unable to open certificate file %s for reading: %s\n", $3, strerror(ret));504 TRACE_DEBUG_ERROR("Unable to open certificate file %s for reading: %s\n", $3, strerror(ret)); 505 505 yyerror (&yylloc, conf, "Error on file name"); 506 506 YYERROR; … … 510 510 if (fd == NULL) { 511 511 int ret = errno; 512 TRACE_DEBUG (INFO,"Unable to open private key file %s for reading: %s\n", $5, strerror(ret));512 TRACE_DEBUG_ERROR("Unable to open private key file %s for reading: %s\n", $5, strerror(ret)); 513 513 yyerror (&yylloc, conf, "Error on file name"); 514 514 YYERROR; … … 533 533 if (fd == NULL) { 534 534 int ret = errno; 535 TRACE_DEBUG (INFO,"Unable to open CA file %s for reading: %s\n", $3, strerror(ret));535 TRACE_DEBUG_ERROR("Unable to open CA file %s for reading: %s\n", $3, strerror(ret)); 536 536 yyerror (&yylloc, conf, "Error on file name"); 537 537 YYERROR; … … 573 573 if (fd == NULL) { 574 574 int ret = errno; 575 TRACE_DEBUG (INFO,"Unable to open CRL file %s for reading: %s\n", $3, strerror(ret));575 TRACE_DEBUG_ERROR("Unable to open CRL file %s for reading: %s\n", $3, strerror(ret)); 576 576 yyerror (&yylloc, conf, "Error on file name"); 577 577 YYERROR; … … 616 616 &err_pos), 617 617 { yyerror (&yylloc, conf, "Error setting Priority parameter."); 618 fprintf(stderr,"Error at position : %s\n", err_pos);618 TRACE_DEBUG_ERROR("Error at position : %s\n", err_pos); 619 619 YYERROR; } ); 620 620 } … … 633 633 if (fd == NULL) { 634 634 int ret = errno; 635 TRACE_DEBUG (INFO,"Unable to open DH file %s for reading: %s\n", $3, strerror(ret));635 TRACE_DEBUG_ERROR("Unable to open DH file %s for reading: %s\n", $3, strerror(ret)); 636 636 yyerror (&yylloc, conf, "Error on file name"); 637 637 YYERROR; -
libfdcore/messages.c
r892 r924 159 159 CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_FIRST_CHILD, avp ) ); 160 160 161 /* Save the session associated with the message */ 162 CHECK_FCT( fd_msg_sess_set( msg, sess) ); 163 161 164 /* Done! */ 162 165 return 0; … … 284 287 hdr->msg_flags |= CMD_FLAG_ERROR; 285 288 else 286 hdr->msg_flags &= !CMD_FLAG_ERROR;289 hdr->msg_flags &= ~ CMD_FLAG_ERROR; 287 290 } 288 291 -
libfdcore/peers.c
r947 r950 549 549 ev_data->validate = !found; 550 550 551 CHECK_FCT_DO( ret = fd_event_send(peer->p_events, FDEVP_CNX_INCOMING, sizeof( ev_data), ev_data), goto out );551 CHECK_FCT_DO( ret = fd_event_send(peer->p_events, FDEVP_CNX_INCOMING, sizeof(*ev_data), ev_data), goto out ); 552 552 553 553 out: -
libfdcore/sctp.c
r946 r950 654 654 if (ep->sa.sa_family == AF_INET6) 655 655 #else /* SCTP_USE_MAPPED_ADDRESSES */ 656 if (target_family == AF_INET6) {656 if (target_family == AF_INET6) 657 657 #endif /* SCTP_USE_MAPPED_ADDRESSES */ 658 658 sz = sizeof(sSA6); … … 1087 1087 /* We will loop while all data is not received. */ 1088 1088 incomplete: 1089 if (datasize == bufsz - sizeof(struct timespec)) {1089 while (datasize + sizeof(struct timespec) >= bufsz ) { 1090 1090 /* The buffer is full, enlarge it */ 1091 1091 bufsz += mempagesz; -
libfdproto/CMakeLists.txt
r836 r922 6 6 fdproto-internal.h 7 7 dictionary.c 8 dictionary_functions.c 8 9 dispatch.c 9 10 fifo.c -
libfdproto/fdproto-internal.h
r909 r924 70 70 int fd_sess_reclaim_msg ( struct session ** session ); 71 71 72 72 73 /* For dump routines into string buffers */ 73 74 #include <stdarg.h> -
libfdproto/messages.c
r903 r924 106 106 #define _A(_x) ((struct avp *)(_x)) 107 107 /* Check the type and eyecatcher */ 108 #define CHECK_AVP(_x) ((_ C(_x)->type == MSG_AVP) && (_A(_x)->avp_eyec == MSG_AVP_EYEC))108 #define CHECK_AVP(_x) ((_x) && (_C(_x)->type == MSG_AVP) && (_A(_x)->avp_eyec == MSG_AVP_EYEC)) 109 109 110 110 /* The following structure represents an instance of a message (command and children AVPs). */ … … 239 239 if (new->avp_rawlen) { 240 240 CHECK_MALLOC( new->avp_rawdata = malloc(new->avp_rawlen) ); 241 memset(new->avp_rawdata, 0x FF, new->avp_rawlen);241 memset(new->avp_rawdata, 0x00, new->avp_rawlen); 242 242 } 243 243 } … … 1216 1216 } 1217 1217 1218 /* Associate a session with a message, use only when the session was just created */ 1219 int fd_msg_sess_set(struct msg * msg, struct session * session) 1220 { 1221 TRACE_ENTRY("%p %p", msg, session); 1222 1223 /* Check we received valid parameters */ 1224 CHECK_PARAMS( CHECK_MSG(msg) ); 1225 CHECK_PARAMS( session ); 1226 CHECK_PARAMS( msg->msg_sess == NULL ); 1227 1228 msg->msg_sess = session; 1229 return 0; 1230 } 1231 1218 1232 1219 1233 /* Retrieve the session of the message */ … … 1261 1275 1262 1276 /* Resolve the session and we are done */ 1263 CHECK_FCT( fd_sess_fromsid_msg ( avp->avp_public.avp_value->os.data, avp->avp_public.avp_value->os.len, &msg->msg_sess, new) ); 1264 *session = msg->msg_sess; 1277 if (avp->avp_public.avp_value->os.len > 0) { 1278 CHECK_FCT( fd_sess_fromsid_msg ( avp->avp_public.avp_value->os.data, avp->avp_public.avp_value->os.len, &msg->msg_sess, new) ); 1279 *session = msg->msg_sess; 1280 } else { 1281 TRACE_DEBUG(FULL, "Session-Id AVP with 0-byte length found in message %p", msg); 1282 *session = NULL; 1283 } 1265 1284 1266 1285 return 0; … … 1648 1667 struct avp * avp; 1649 1668 1650 if (buflen - offset < =AVPHDRSZ_NOVEND) {1669 if (buflen - offset < AVPHDRSZ_NOVEND) { 1651 1670 TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes", buflen - offset); 1652 1671 return EBADMSG; … … 1666 1685 1667 1686 if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) { 1668 if (buflen - offset < =4) {1687 if (buflen - offset < 4) { 1669 1688 TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes for vendor and data", buflen - offset); 1670 1689 free(avp); … … 1676 1695 1677 1696 /* Check there is enough remaining data in the buffer */ 1678 if (buflen - offset < avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags)) { 1697 if ( (avp->avp_public.avp_len > GETAVPHDRSZ(avp->avp_public.avp_flags)) 1698 && (buflen - offset < avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags))) { 1679 1699 TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes for data, and avp data size is %d", 1680 1700 buflen - offset, -
libfdproto/sessions.c
r788 r924 360 360 361 361 362 /* Create a new session object with the default timeout value, and link it */362 /* Create a new session object with the default timeout value, and link it. The refcount is increased by 1, whether the session existed or not */ 363 363 int fd_sess_new ( struct session ** session, DiamId_t diamid, size_t diamidlen, uint8_t * opt, size_t optlen ) 364 364 { … … 461 461 462 462 fd_list_insert_before(li, &sess->chain_h); /* hash table */ 463 sess->msg_cnt++; 463 464 } else { 464 465 free(sid); 466 467 CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) ); 468 (*session)->msg_cnt++; 469 CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) ); 470 465 471 /* it was found: was it previously destroyed? */ 466 472 if ((*session)->is_destroyed == 0) { … … 469 475 } else { 470 476 /* the session was marked destroyed, let's re-activate it. */ 471 TODO("Re-creating a deleted session. Should investigate if this can lead to an issue... (need more feedback)");472 477 sess = *session; 478 sess->is_destroyed = 0; 473 479 474 480 /* update the expiry time */ … … 501 507 502 508 out: 503 ; 509 ; 504 510 pthread_cleanup_pop(0); 505 511 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) ); … … 512 518 } 513 519 514 /* Find or create a session */515 int fd_sess_fromsid ( uint8_t * sid, size_t len, struct session ** session, int * new)520 /* Find or create a session -- the msg refcount is increased */ 521 int fd_sess_fromsid_msg ( uint8_t * sid, size_t len, struct session ** session, int * new) 516 522 { 517 523 int ret; … … 802 808 803 809 /* For the messages module */ 804 int fd_sess_fromsid _msg( uint8_t * sid, size_t len, struct session ** session, int * new)810 int fd_sess_fromsid ( uint8_t * sid, size_t len, struct session ** session, int * new) 805 811 { 806 812 TRACE_ENTRY("%p %zd %p %p", sid, len, session, new); … … 808 814 809 815 /* Get the session object */ 810 CHECK_FCT( fd_sess_fromsid ( sid, len, session, new) ); 811 812 /* Increase count */ 813 CHECK_FCT( fd_sess_ref_msg ( *session ) ); 814 816 CHECK_FCT( fd_sess_fromsid_msg ( sid, len, session, new) ); 817 818 /* Decrease the refcount */ 819 CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) ); 820 (*session)->msg_cnt--; /* was increased in fd_sess_new */ 821 CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) ); 822 815 823 /* Done */ 816 824 return 0; … … 833 841 { 834 842 int reclaim; 843 uint32_t hash; 835 844 836 845 TRACE_ENTRY("%p", session); 837 846 CHECK_PARAMS( session && VALIDATE_SI(*session) ); 838 847 848 /* Lock the hash line to avoid possibility that session is freed while we are reclaiming */ 849 hash = (*session)->hash; 850 CHECK_POSIX( pthread_mutex_lock( H_LOCK(hash)) ); 851 pthread_cleanup_push( fd_cleanup_mutex, H_LOCK(hash) ); 852 839 853 /* Update the msg refcount */ 840 854 CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) ); … … 843 857 CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) ); 844 858 859 /* Ok, now unlock the hash line */ 860 pthread_cleanup_pop( 0 ); 861 CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) ); 862 863 /* and reclaim if no message references the session anymore */ 845 864 if (reclaim == 1) { 846 865 CHECK_FCT(fd_sess_reclaim ( session ));
Note: See TracChangeset
for help on using the changeset viewer.