Changes in / [1306:0d15dad33f0b:1307:7a2ab0087788] in freeDiameter
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
.hgtags
r1282 r1293 69 69 f937feb727347445f8afb7759a97e34c76c0ba7b 1.2.0 70 70 ab6457399be2762b3e85bd173ba754ff758ef060 1.2.1-rc1 71 043b894b0511b6beb155576e9e2c509a21be8360 proposed_merged 72 0000000000000000000000000000000000000000 proposed_merged 73 13948c684c354d8c891ca5e2a5f1d76d1f176afe 1.2.1-rc2 -
contrib/debian/changelog
r1234 r1304 1 freediameter (1.2.1) UNRELEASED; urgency=low 2 3 * New extension: rt_randomize (load-balancing on possible destinations) 4 * New contrib: Gx extension. 5 * rt_redirect.fdx and rt_load_balance.fdx improvement: use a hash table. Thanks Thomas. 6 * New hook HOOK_MESSAGE_SENDING to give a last chance to edit messages before they are sent. 7 This will be mostly used for enforcing interoperability constraints on non-compliant peers. 8 * Simplified log output. Old output can be recovered with DEBUG_WITH_META build option. 9 * Updated the internal counters for finer control on the load. 10 * Fixes in message expiry mechanism. 11 * Bug fixes in error messages generation. 12 * Improvements on shutdown sequence handling. 13 * Improvements to the dict_dcca_* extensions. 14 * Improved default CMake configuration. 15 * Fixes for a few newer operating systems compatibility. 16 * Fixed default secure Diameter port number 5868 instead of5658 (errata of RFC 6733) 17 18 -- Sebastien Decugis <sdecugis@freediameter.net> Sat, 30 Jan 2016 23:38:03 +0800 19 1 20 freediameter (1.2.0) UNRELEASED; urgency=low 2 21 -
doc/freediameter.conf.sample
r1246 r1304 32 32 # See TLS_old_method for more information about TLS flavours. 33 33 # Note: we use TLS/SCTP instead of DTLS/SCTP at the moment. This will change in future version of freeDiameter. 34 # Default: 5 658. Use 0 to disable.35 #SecPort = 5 658;34 # Default: 5868. Use 0 to disable. 35 #SecPort = 5868; 36 36 37 37 # Use RFC3588 method for TLS protection, where TLS is negociated after CER/CEA exchange is completed … … 238 238 # No_TCP; No_SCTP; No_IP; No_IPv6; Prefer_TCP; TLS_old_method; 239 239 # No_TLS; # assume transparent security instead of TLS. DTLS is not supported yet (will change in future versions). 240 # Port = 5 658; # The port to connect to240 # Port = 5868; # The port to connect to 241 241 # TcTimer = 30; 242 242 # TwTimer = 30; -
extensions/app_radgw/md5.c
r972 r1291 293 293 byteReverse((unsigned char *) ctx->buf, 4); 294 294 os_memcpy(digest, ctx->buf, 16); 295 os_memset(ctx, 0, sizeof( ctx)); /* In case it's sensitive */295 os_memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ 296 296 } 297 297 -
extensions/app_sip/md5.c
r972 r1291 316 316 byteReverse((unsigned char *) ctx->buf, 4); 317 317 os_memcpy(digest, ctx->buf, 16); 318 os_memset(ctx, 0, sizeof( ctx)); /* In case it's sensitive */318 os_memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */ 319 319 } 320 320 -
extensions/dbg_msg_dumps/dbg_msg_dumps.c
r1306 r1307 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 105 105 } 106 106 break; 107 case HOOK_MESSAGE_PARSING_ERROR2: 108 LOG_E("PARSING ERROR, returning:"); 109 LOG_SPLIT(FD_LOG_ERROR, " ", buf, NULL); 110 break; 107 111 case HOOK_MESSAGE_ROUTING_ERROR: 108 112 LOG_E("ROUTING ERROR '%s' for: ", (char *)other); … … 117 121 case HOOK_MESSAGE_RECEIVED: 118 122 LOG_N("RCV from '%s':", peer_name); 123 LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL); 124 break; 125 case HOOK_MESSAGE_SENDING: 126 LOG_N("SNDING to '%s':", peer_name); 119 127 LOG_SPLIT(FD_LOG_NOTICE, " ", buf, NULL); 120 128 break; … … 194 202 } 195 203 break; 204 case HOOK_MESSAGE_PARSING_ERROR2: 205 LOG_E("PARSING ERROR, returning: %s", buf); 206 break; 196 207 case HOOK_MESSAGE_ROUTING_ERROR: 197 208 LOG_E("ROUTING ERROR '%s' for: %s", (char *)other, buf); … … 204 215 case HOOK_MESSAGE_RECEIVED: 205 216 LOG_N("RCV from '%s': %s", peer_name, buf); 217 break; 218 case HOOK_MESSAGE_SENDING: 219 LOG_N("SNDING to '%s': %s", peer_name, buf); 206 220 break; 207 221 case HOOK_MESSAGE_SENT: … … 273 287 } 274 288 break; 289 case HOOK_MESSAGE_PARSING_ERROR2: 290 LOG_E("PARSING ERROR, returning: %s", buf); 291 break; 275 292 case HOOK_MESSAGE_ROUTING_ERROR: 276 293 LOG_E("ROUTING ERROR '%s' for: %s", (char *)other, buf); … … 283 300 case HOOK_MESSAGE_RECEIVED: 284 301 LOG_N("RCV from '%s': %s", peer_name, buf); 302 break; 303 case HOOK_MESSAGE_SENDING: 304 LOG_N("SNDING to '%s': %s", peer_name, buf); 285 305 break; 286 306 case HOOK_MESSAGE_SENT: … … 341 361 } 342 362 343 mask_errors = HOOK_MASK( HOOK_MESSAGE_FAILOVER, HOOK_MESSAGE_PARSING_ERROR, HOOK_MESSAGE_ ROUTING_ERROR, HOOK_MESSAGE_DROPPED );344 mask_sndrcv = HOOK_MASK( HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_SENT ); 363 mask_errors = HOOK_MASK( HOOK_MESSAGE_FAILOVER, HOOK_MESSAGE_PARSING_ERROR, HOOK_MESSAGE_PARSING_ERROR2, HOOK_MESSAGE_ROUTING_ERROR, HOOK_MESSAGE_DROPPED ); 364 mask_sndrcv = HOOK_MASK( HOOK_MESSAGE_RECEIVED, HOOK_MESSAGE_SENT ); /* We don t access SENDING hook here */ 345 365 mask_routing= HOOK_MASK( HOOK_MESSAGE_LOCAL, HOOK_MESSAGE_ROUTING_FORWARD, HOOK_MESSAGE_ROUTING_LOCAL ); 346 366 mask_peers = HOOK_MASK( HOOK_PEER_CONNECT_FAILED, HOOK_PEER_CONNECT_SUCCESS ); -
extensions/test_app/ta_bench.c
r1206 r1294 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 37 37 38 38 #include "test_app.h" 39 39 #include <stdio.h> 40 41 #ifndef __APPLE__ /* they deprecated the semaphore there... */ 40 42 #include <semaphore.h> 41 #include <stdio.h> 43 44 #define my_sem_t sem_t 45 #define my_sem_init sem_init 46 #define my_sem_destroy sem_destroy 47 #define my_sem_timedwait sem_timedwait 48 #define my_sem_post sem_post 49 50 #else // on APPLE 51 #include <sched.h> 52 #include <dispatch/dispatch.h> 53 54 #define my_sem_t dispatch_semaphore_t 55 56 static int my_sem_init(my_sem_t * s, int pshared, unsigned int value ) { 57 *s = dispatch_semaphore_create(value); 58 if (*s == NULL) 59 return ENOMEM; 60 return 0; 61 } 62 63 static int my_sem_destroy(my_sem_t *s) { 64 dispatch_release(*s); 65 *s = NULL; 66 return 0; 67 } 68 69 static int my_sem_timedwait(my_sem_t * s, struct timespec *ts) { 70 struct timespec tsn; 71 int64_t nsec; 72 dispatch_time_t when; 73 74 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &tsn) ); 75 76 nsec = (ts->tv_sec * 1000000000) + ts->tv_nsec 77 - (tsn.tv_sec * 1000000000) - tsn.tv_nsec; 78 79 when = dispatch_time ( DISPATCH_TIME_NOW, nsec ); 80 81 return dispatch_semaphore_wait ( *s, when ) ? ETIMEDOUT : 0; 82 } 83 84 static int my_sem_post(my_sem_t *s) { 85 dispatch_semaphore_signal(*s); 86 return 0; 87 } 88 89 #endif // APPLE 90 91 42 92 43 93 struct ta_mess_info { … … 46 96 }; 47 97 48 static sem_t ta_sem; /* To handle the concurrency */98 static my_sem_t ta_sem; /* To handle the concurrency */ 49 99 50 100 /* Cb called when an answer is received */ … … 110 160 111 161 /* Post the semaphore */ 112 CHECK_SYS_DO( sem_post(&ta_sem), );162 CHECK_SYS_DO( my_sem_post(&ta_sem), ); 113 163 114 164 return; … … 214 264 do { 215 265 /* Do not create more that NB_CONCURRENT_MESSAGES in paralel */ 216 int ret = sem_timedwait(&ta_sem, &end_time);266 int ret = my_sem_timedwait(&ta_sem, &end_time); 217 267 if (ret == -1) { 218 268 ret = errno; … … 270 320 int ta_bench_init(void) 271 321 { 272 CHECK_SYS( sem_init( &ta_sem, 0, ta_conf->bench_concur) );322 CHECK_SYS( my_sem_init( &ta_sem, 0, ta_conf->bench_concur) ); 273 323 274 324 CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.bench", ta_bench_start ) ); … … 281 331 // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ ); 282 332 283 CHECK_SYS_DO( sem_destroy(&ta_sem), );333 CHECK_SYS_DO( my_sem_destroy(&ta_sem), ); 284 334 285 335 return; -
extensions/test_app/ta_cli.c
r1214 r1305 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 71 71 72 72 CHECK_FCT_DO( fd_sess_state_retrieve( ta_cli_reg, sess, &mi ), return ); 73 TRACE_DEBUG( INFO, "%p %p", mi, data);74 73 ASSERT( (void *)mi == data ); 75 74 } -
freeDiameterd/main.c
r1182 r1305 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 172 172 /* Loop on arguments */ 173 173 while (1) { 174 c = getopt_long (argc, argv, "hVc:dql: M:", long_options, &option_index);174 c = getopt_long (argc, argv, "hVc:dql:f:F:g:", long_options, &option_index); 175 175 if (c == -1) 176 176 break; /* Exit from the loop. */ … … 208 208 #ifdef DEBUG 209 209 fd_debug_one_function = optarg; 210 fd_g_debug_lvl = FD_LOG_DEBUG; 210 211 #else /* DEBUG */ 211 212 fprintf(stderr, "Error: must compile with DEBUG support to use --dbg_func feature!\n"); … … 217 218 #ifdef DEBUG 218 219 fd_debug_one_file = basename(optarg); 220 fd_g_debug_lvl = FD_LOG_DEBUG; 219 221 #else /* DEBUG */ 220 222 fprintf(stderr, "Error: must compile with DEBUG support to use --dbg_file feature!\n"); -
include/freeDiameter/CMakeLists.txt
r1289 r1295 16 16 OPTION(ERRORS_ON_TODO "(development) Generate compilation errors on TODO items ?" OFF) 17 17 18 # In DEBUG mode, each log c ontains pid, calling function and file for easy debug. Set to ON to stripthis information.19 OPTION(DEBUG_WITH OUT_META "Stripcalling location in logs?" OFF)18 # In DEBUG mode, each log can contain pid, calling function and file for easy debug. Set to ON to display this information. 19 OPTION(DEBUG_WITH_META "Show calling location in logs?" OFF) 20 20 21 21 # Create the absolute path for searching extensions … … 37 37 OPTION(WORKAROUND_ACCEPT_INVALID_VSAI "Do not reject a CER/CEA with a Vendor-Specific-Application-Id AVP containing both Auth- and Acct- application AVPs?" OFF) 38 38 39 MARK_AS_ADVANCED(DISABLE_SCTP DEBUG_SCTP SCTP_USE_MAPPED_ADDRESSES ERRORS_ON_TODO DEBUG_WITH OUT_META DIAMID_IDNA_IGNORE DIAMID_IDNA_REJECT DISABLE_PEER_EXPIRY WORKAROUND_ACCEPT_INVALID_VSAI)39 MARK_AS_ADVANCED(DISABLE_SCTP DEBUG_SCTP SCTP_USE_MAPPED_ADDRESSES ERRORS_ON_TODO DEBUG_WITH_META DIAMID_IDNA_IGNORE DIAMID_IDNA_REJECT DISABLE_PEER_EXPIRY WORKAROUND_ACCEPT_INVALID_VSAI) 40 40 41 41 ######################## -
include/freeDiameter/freeDiameter-host.h.in
r1237 r1305 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 54 54 #cmakedefine DISABLE_SCTP 55 55 #cmakedefine DEBUG_SCTP 56 #cmakedefine DEBUG_WITH OUT_META56 #cmakedefine DEBUG_WITH_META 57 57 #cmakedefine SCTP_USE_MAPPED_ADDRESSES 58 58 #cmakedefine SCTP_CONNECTX_4_ARGS -
include/freeDiameter/libfdcore.h
r1220 r1305 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2016, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 128 128 129 129 uint16_t cnf_port; /* the local port for legacy Diameter (default: 3868) in host byte order */ 130 uint16_t cnf_port_tls; /* the local port for Diameter/TLS (default: 5 658) in host byte order */130 uint16_t cnf_port_tls; /* the local port for Diameter/TLS (default: 5868) in host byte order */ 131 131 uint16_t cnf_port_3436; /* Open an additional server port to listen to old TLS/SCTP clients (RFC3436, freeDiameter versions < 1.2.0) */ 132 132 uint16_t cnf_sctp_str; /* default max number of streams for SCTP associations (def: 30) */ … … 965 965 */ 966 966 967 HOOK_MESSAGE_SENDING, 968 /* Hook called when a message is about to be sent to a peer. The message pointer cannot be modified here, but the content of the message 969 could still be changed (for example add or remove some AVP. This is the last chance. 970 - {msg} points to the message. Some objects may not have been dictionary resolved. If you 971 try to call fd_msg_parse_dict, it will slow down the operation of the instance. 972 - {peer} is the one the message is being sent to. 973 - {other} is NULL. 974 - {permsgdata} points to existing structure if any, or a new structure otherwise. 975 */ 976 967 977 HOOK_MESSAGE_SENT, 968 978 /* Hook called when a message has been sent to a peer. The message might be freed as soon as the hook function returns, … … 993 1003 - {permsgdata} points to existing structure associated with this message (or new structure if no previous hook was registered). 994 1004 */ 995 1005 996 1006 HOOK_MESSAGE_ROUTING_ERROR, 997 1007 /* Hook called when a message being processed by the routing thread meets an error such as no remaining available peer for sending, based on routing callbacks decisions (maybe after retries). … … 1049 1059 */ 1050 1060 1051 #define HOOK_LAST HOOK_PEER_CONNECT_SUCCESS 1061 HOOK_MESSAGE_PARSING_ERROR2, 1062 /* Hook called after an error message has been generated due to a dictionary parsing error. 1063 - {msg} points to the error message that has been generated. 1064 - {peer} is NULL. You can still retrieve the source from the message itself. 1065 - {other} is NULL 1066 - {permsgdata} points to existing structure associated with this message (or new structure if no previous hook was registered). 1067 Use this hook if you need to populate more data in the error being returned, from the error message. 1068 (e.g. some AVP need to be added to replies even if error case. 1069 */ 1070 #define HOOK_LAST HOOK_MESSAGE_PARSING_ERROR2 1052 1071 }; 1053 1072 -
include/freeDiameter/libfdproto.h
r1281 r1304 110 110 111 111 #define DIAMETER_PORT 3868 112 #define DIAMETER_SECURE_PORT 5 658112 #define DIAMETER_SECURE_PORT 5868 113 113 114 114 … … 290 290 #endif /* __PRETTY_FUNCTION__ */ 291 291 292 /* A version of __FILE__ without the full path */292 /* A version of __FILE__ without the full path. This is specific to each C file being compiled */ 293 293 static char * file_bname = NULL; 294 294 static char * file_bname_init(char * full) { file_bname = basename(full); return file_bname; } … … 298 298 299 299 /* In DEBUG mode, we add meta-information along each trace. This makes multi-threading problems easier to debug. */ 300 #if (defined(DEBUG) && !defined(DEBUG_WITHOUT_META))300 #if (defined(DEBUG) && defined(DEBUG_WITH_META)) 301 301 # define STD_TRACE_FMT_STRING "pid:%s in %s@%s:%d: " 302 302 # define STD_TRACE_FMT_ARGS , ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"), __PRETTY_FUNCTION__, __STRIPPED_FILE__, __LINE__ 303 #else /* DEBUG && !DEBUG_WITHOUT_META */303 #else /* DEBUG && DEBUG_WITH_META */ 304 304 # define STD_TRACE_FMT_STRING "" 305 305 # define STD_TRACE_FMT_ARGS 306 #endif /* DEBUG && !DEBUG_WITHOUT_META */306 #endif /* DEBUG && DEBUG_WITH_META */ 307 307 308 308 /************************* … … 1259 1259 typedef int (*dict_avpdata_encode) (void * data, union avp_value * val); 1260 1260 1261 /* 1262 * CALLBACK: dict_avpdata_check 1263 * 1264 * PARAMETERS: 1265 * val : Pointer to the AVP value that was received and needs to be sanity checked. 1266 * data : a parameter stored in the type structure (to enable more generic check functions) 1267 * error_msg: upon erroneous value, a string describing the error can be returned here (it will be strcpy by caller). This description will be returned in the error message, if any. 1268 * 1269 * DESCRIPTION: 1270 * This callback can be provided with a derived type in order to improve the operation of the 1271 * fd_msg_parse_dict function. When this callback is present, the value of the AVP that has 1272 * been parsed is passed to this function for finer granularity check. For example for some 1273 * speccific AVP, the format of an OCTETSTRING value can be further checked, or the 1274 * interger value can be verified. 1275 * 1276 * RETURN VALUE: 1277 * 0 : The value is valid. 1278 * !0 : An error occurred, the error code is returned. It is advised to return EINVAL on incorrect val 1279 */ 1280 typedef int (*dict_avpdata_check) (void * data, union avp_value * val, char ** error_msg); 1281 1282 1261 1283 1262 1284 /* Type to hold data associated to a derived AVP data type */ … … 1267 1289 dict_avpdata_encode type_encode; /* cb to convert formatted data into an AVP value (or NULL) */ 1268 1290 DECLARE_FD_DUMP_PROTOTYPE((*type_dump), union avp_value * val); /* cb called by fd_msg_dump_* for this type of data (if != NULL). Returned string must be freed. */ 1291 dict_avpdata_check type_check; 1292 void * type_check_param; 1269 1293 }; 1270 1294 … … 1293 1317 DECLARE_FD_DUMP_PROTOTYPE(fd_dictfct_Time_dump, union avp_value * avp_value); 1294 1318 1319 1320 /* For string AVP, the following type_check function provides simple basic check for specific characters presence, e.g. use "@." for trivial email address check */ 1321 int fd_dictfct_CharInOS_check(void * data, union avp_value * val, char ** error_msg); 1295 1322 1296 1323 -
libfdcore/hooks.c
r1306 r1307 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 345 345 } 346 346 347 case HOOK_MESSAGE_SENDING: { 348 LOG_A("SENDING message to '%s'", peer ? peer->p_hdr.info.pi_diamid : "<unknown>"); 349 break; 350 } 351 347 352 case HOOK_MESSAGE_SENT: { 348 353 CHECK_MALLOC_DO(fd_msg_dump_summary(&hook_default_buf, &hook_default_len, NULL, msg, NULL, 0, 1), break); … … 378 383 } 379 384 385 case HOOK_MESSAGE_PARSING_ERROR2: { 386 CHECK_MALLOC_DO(fd_msg_dump_treeview(&hook_default_buf, &hook_default_len, NULL, msg, NULL, 0, 1), break); 387 388 LOG_E("Returning following message after parsing error:"); 389 LOG_SPLIT(FD_LOG_ERROR, " ", hook_default_buf, NULL); 390 break; 391 } 392 380 393 case HOOK_MESSAGE_ROUTING_ERROR: { 381 394 CHECK_MALLOC_DO(fd_msg_dump_treeview(&hook_default_buf, &hook_default_len, NULL, msg, NULL, 0, 1), break); -
libfdcore/p_out.c
r1238 r1305 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 166 166 TRACE_ENTRY("%p %p %p", msg, cnx, peer); 167 167 CHECK_PARAMS( msg && *msg && (cnx || (peer && peer->p_cnxctx))); 168 169 fd_hook_call(HOOK_MESSAGE_SENDING, *msg, peer, NULL, fd_msg_pmdl_get(*msg)); 168 170 169 171 if (update_reqin_cnt && peer) { -
libfdcore/routing_dispatch.c
r1283 r1301 454 454 } else { 455 455 if (!msgptr) { 456 fd_hook_call(HOOK_MESSAGE_PARSING_ERROR2, error, NULL, NULL, fd_msg_pmdl_get(error)); 456 457 /* error now contains the answer message to send back */ 457 458 CHECK_FCT( fd_fifo_post(fd_g_outgoing, &error) ); -
libfdproto/dictionary_functions.c
r1284 r1300 359 359 } 360 360 361 /* Check that a given AVP value contains all the characters from data in the same order */ 362 static char error_message[80]; 363 int fd_dictfct_CharInOS_check(void * data, union avp_value * val, char ** error_msg) 364 { 365 char * inChar = data; 366 char * inData = (char *)val->os.data; 367 int i = 0; 368 CHECK_PARAMS(data); 369 while (*inChar != '\0') { 370 while (i < val->os.len) { 371 if (*inChar == inData[i++]) { 372 inChar++; 373 break; 374 } 375 } 376 if (i >= val->os.len) 377 break; 378 } 379 if (*inChar == '\0') 380 return 0; 381 382 if (error_msg) { 383 snprintf(error_message, sizeof(error_message), "Could not find '%c' in AVP", *inChar); 384 *error_msg = error_message; 385 } 386 return EBADMSG; 387 } -
libfdproto/log.c
r1243 r1305 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 96 96 /* add timestamp */ 97 97 printf("%s ", fd_log_time(NULL, buf, sizeof(buf), 98 #if (defined(DEBUG) && !defined(DEBUG_WITHOUT_META))98 #if (defined(DEBUG) && defined(DEBUG_WITH_META)) 99 99 1, 1 100 #else /* (defined(DEBUG) && !defined(DEBUG_WITHOUT_META)) */100 #else /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */ 101 101 0, 0 102 #endif /* (defined(DEBUG) && !defined(DEBUG_WITHOUT_META)) */102 #endif /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */ 103 103 )); 104 104 /* Use colors on stdout ? */ -
libfdproto/messages.c
r1248 r1305 3 3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * 4 4 * * 5 * Copyright (c) 201 3, WIDE Project and NICT *5 * Copyright (c) 2015, WIDE Project and NICT * 6 6 * All rights reserved. * 7 7 * * … … 232 232 struct dict_avp_data dictdata; 233 233 234 CHECK_FCT ( fd_dict_getval(model, &dictdata));234 CHECK_FCT_DO( fd_dict_getval(model, &dictdata), { free(new); return __ret__; } ); 235 235 236 236 new->avp_model = model; … … 248 248 new->avp_rawlen = (*avp)->avp_public.avp_len - GETAVPHDRSZ( (*avp)->avp_public.avp_flags ); 249 249 if (new->avp_rawlen) { 250 CHECK_MALLOC ( new->avp_rawdata = malloc(new->avp_rawlen));250 CHECK_MALLOC_DO( new->avp_rawdata = malloc(new->avp_rawlen), { free(new); return __ret__; } ); 251 251 memset(new->avp_rawdata, 0x00, new->avp_rawlen); 252 252 } … … 286 286 struct dict_object *dictappl; 287 287 288 CHECK_FCT ( fd_dict_getdict(model, &dict));289 CHECK_FCT ( fd_dict_getval(model, &dictdata));288 CHECK_FCT_DO( fd_dict_getdict(model, &dict), { free(new); return __ret__; } ); 289 CHECK_FCT_DO( fd_dict_getval(model, &dictdata), { free(new); return __ret__; } ); 290 290 291 291 new->msg_model = model; … … 294 294 295 295 /* Initialize application from the parent, if any */ 296 CHECK_FCT ( fd_dict_search( dict, DICT_APPLICATION, APPLICATION_OF_COMMAND, model, &dictappl, 0));296 CHECK_FCT_DO( fd_dict_search( dict, DICT_APPLICATION, APPLICATION_OF_COMMAND, model, &dictappl, 0), { free(new); return __ret__; } ); 297 297 if (dictappl != NULL) { 298 298 struct dict_application_data appdata; 299 CHECK_FCT ( fd_dict_getval(dictappl, &appdata));299 CHECK_FCT_DO( fd_dict_getval(dictappl, &appdata), { free(new); return __ret__; } ); 300 300 new->msg_public.msg_appl = appdata.application_id; 301 301 } … … 365 365 366 366 if (!sess_id_avp) { 367 CHECK_FCT ( fd_dict_search( dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sess_id_avp, ENOENT));368 } 369 CHECK_FCT ( fd_sess_getsid ( sess, &sid, &sidlen ));370 CHECK_FCT ( fd_msg_avp_new ( sess_id_avp, 0, &avp ));367 CHECK_FCT_DO( fd_dict_search( dict, DICT_AVP, AVP_BY_NAME, "Session-Id", &sess_id_avp, ENOENT), { free(ans); return __ret__; } ); 368 } 369 CHECK_FCT_DO( fd_sess_getsid ( sess, &sid, &sidlen ), { free(ans); return __ret__; } ); 370 CHECK_FCT_DO( fd_msg_avp_new ( sess_id_avp, 0, &avp ), { free(ans); return __ret__; } ); 371 371 val.os.data = sid; 372 372 val.os.len = sidlen; 373 CHECK_FCT ( fd_msg_avp_setvalue( avp, &val ));374 CHECK_FCT ( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ));373 CHECK_FCT_DO( fd_msg_avp_setvalue( avp, &val ), { free(avp); free(ans); return __ret__; } ); 374 CHECK_FCT_DO( fd_msg_avp_add( ans, MSG_BRW_FIRST_CHILD, avp ), { free(avp); free(ans); return __ret__; } ); 375 375 ans->msg_sess = sess; 376 CHECK_FCT ( fd_sess_ref_msg(sess));376 CHECK_FCT_DO( fd_sess_ref_msg(sess), { free(ans); return __ret__; } ); 377 377 } 378 378 … … 383 383 struct fd_list avpcpylist = FD_LIST_INITIALIZER(avpcpylist); 384 384 385 CHECK_FCT ( fd_msg_browse(qry, MSG_BRW_FIRST_CHILD, &avp, NULL));385 CHECK_FCT_DO( fd_msg_browse(qry, MSG_BRW_FIRST_CHILD, &avp, NULL) , { free(ans); return __ret__; } ); 386 386 while (avp) { 387 387 if ( (avp->avp_public.avp_code == AC_PROXY_INFO) … … 394 394 395 395 /* Create a buffer with the content of the AVP. This is easier than going through the list */ 396 CHECK_FCT ( fd_msg_update_length(avp));397 CHECK_MALLOC ( buf = malloc(avp->avp_public.avp_len));398 CHECK_FCT ( bufferize_avp(buf, avp->avp_public.avp_len, &offset, avp));396 CHECK_FCT_DO( fd_msg_update_length(avp), { free(ans); return __ret__; } ); 397 CHECK_MALLOC_DO( buf = malloc(avp->avp_public.avp_len), { free(ans); return __ret__; } ); 398 CHECK_FCT_DO( bufferize_avp(buf, avp->avp_public.avp_len, &offset, avp), { free(buf); free(ans); return __ret__; } ); 399 399 400 400 /* Now we parse this buffer to create a copy AVP */ 401 CHECK_FCT ( parsebuf_list(buf, avp->avp_public.avp_len, &avpcpylist));401 CHECK_FCT_DO( parsebuf_list(buf, avp->avp_public.avp_len, &avpcpylist), { free(buf); free(ans); return __ret__; } ); 402 402 403 403 /* Parse dictionary objects now to remove the dependency on the buffer */ 404 CHECK_FCT ( parsedict_do_chain(dict, &avpcpylist, 0, &pei));404 CHECK_FCT_DO( parsedict_do_chain(dict, &avpcpylist, 0, &pei), { /* leaking the avpcpylist -- this should never happen anyway */ free(buf); free(ans); return __ret__; } ); 405 405 406 406 /* Done for this AVP */ … … 411 411 } 412 412 /* move to next AVP in the message, we can have several Proxy-Info instances */ 413 CHECK_FCT ( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL));413 CHECK_FCT_DO( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL), { free(ans); return __ret__; } ); 414 414 } 415 415 } … … 2037 2037 { 2038 2038 struct dict_avp_data dictdata; 2039 struct dict_type_data derivedtypedata; 2040 struct dict_object * avp_derived_type = NULL; 2039 2041 uint8_t * source; 2040 2042 … … 2217 2219 break; 2218 2220 2221 } 2222 2223 /* Is there a derived type check function ? */ 2224 CHECK_FCT ( fd_dict_search ( dict, DICT_TYPE, TYPE_OF_AVP, avp->avp_model, &avp_derived_type, 0) ); 2225 if (avp_derived_type) { 2226 CHECK_FCT( fd_dict_getval(avp_derived_type, &derivedtypedata) ); 2227 if (derivedtypedata.type_check != NULL) { 2228 char * err; 2229 int ret = (*derivedtypedata.type_check)( derivedtypedata.type_check_param, &avp->avp_storage, &err ); 2230 2231 if (ret != 0) { 2232 TRACE_DEBUG(INFO, "The AVP failed to pass the dictionary validation"); 2233 if (error_info) { 2234 error_info->pei_errcode = "DIAMETER_INVALID_AVP_VALUE"; 2235 error_info->pei_avp = avp; 2236 strncpy(error_message, err, sizeof(error_message)); 2237 error_info->pei_message = error_message; 2238 } else { 2239 char * buf = NULL; 2240 size_t buflen; 2241 CHECK_MALLOC(fd_msg_dump_treeview(&buf, &buflen, NULL, avp, NULL, 0, 0)); 2242 LOG_E("Invalid AVP: %s", buf); 2243 free(buf); 2244 } 2245 return ret; /* should we just return EBADMSG? */ 2246 } 2247 } 2219 2248 } 2220 2249 -
tests/testmesg.c
r1281 r1300 309 309 #endif 310 310 } 311 312 { 313 struct dict_object * type = NULL; 314 struct dict_type_data type_data = { AVP_TYPE_OCTETSTRING, "OS test2", NULL, NULL, NULL, fd_dictfct_CharInOS_check, "@." }; 315 struct dict_avp_data avp_data = { 73575, 73565, "AVP Test - os2", AVP_FLAG_VENDOR, AVP_FLAG_VENDOR, AVP_TYPE_OCTETSTRING }; 316 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_TYPE, &type_data , NULL, &type ) ); 317 CHECK( 0, fd_dict_new ( fd_g_config->cnf_dict, DICT_AVP, &avp_data , type, NULL ) ); 318 } 319 311 320 #if 0 312 321 { … … 753 762 /* reset */ 754 763 CHECK( 0, fd_msg_free ( msg ) ); 764 } 765 766 /* Test with a type verifier */ 767 { 768 struct fd_pei error_info; 769 CPYBUF(); 770 buf_cpy[103] = 0x67; /* Replaced AVP code = 0x00011F67, OS test2 type in the dictionary */ 771 772 /* Check that we cannot support this message now */ 773 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); 774 CHECK( EBADMSG, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); 775 776 /* reset */ 777 CHECK( 0, fd_msg_free ( msg ) ); 778 779 CPYBUF(); 780 buf_cpy[103] = 0x67; /* Replaced AVP code = 0x00011F67, OS test2 type in the dictionary */ 781 782 /* Check error reporting works */ 783 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); 784 CHECK( EBADMSG, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, &error_info ) ); 785 786 #if 1 787 fd_log_debug("Error reported: %s\n in AVP: %s", error_info.pei_message, fd_msg_dump_treeview(FD_DUMP_TEST_PARAMS, error_info.pei_avp, fd_g_config->cnf_dict, 0, 1)); 788 #endif 789 790 /* reset */ 791 CHECK( 0, fd_msg_free ( msg ) ); 792 793 CPYBUF(); 794 buf_cpy[103] = 0x67; /* Replaced AVP code = 0x00011F67, OS test2 type in the dictionary */ 795 buf_cpy[130] = '@'; 796 buf_cpy[140] = '.'; /* now we comply to the constraints */ 797 798 /* Check that we cannot support this message now */ 799 CHECK( 0, fd_msg_parse_buffer( &buf_cpy, 344, &msg) ); 800 CHECK( 0, fd_msg_parse_dict( msg, fd_g_config->cnf_dict, NULL ) ); 801 802 /* reset */ 803 CHECK( 0, fd_msg_free ( msg ) ); 804 805 755 806 } 756 807 … … 1399 1450 } 1400 1451 1401 1402 1452 /* That's all for the tests yet */ 1403 1453 PASSTEST();
Note: See TracChangeset
for help on using the changeset viewer.