Navigation


Changes in / [1306:0d15dad33f0b:1307:7a2ab0087788] in freeDiameter


Ignore:
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • .hgtags

    r1282 r1293  
    6969f937feb727347445f8afb7759a97e34c76c0ba7b 1.2.0
    7070ab6457399be2762b3e85bd173ba754ff758ef060 1.2.1-rc1
     71043b894b0511b6beb155576e9e2c509a21be8360 proposed_merged
     720000000000000000000000000000000000000000 proposed_merged
     7313948c684c354d8c891ca5e2a5f1d76d1f176afe 1.2.1-rc2
  • contrib/debian/changelog

    r1234 r1304  
     1freediameter (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
    120freediameter (1.2.0) UNRELEASED; urgency=low
    221
  • doc/freediameter.conf.sample

    r1246 r1304  
    3232# See TLS_old_method for more information about TLS flavours.
    3333# Note: we use TLS/SCTP instead of DTLS/SCTP at the moment. This will change in future version of freeDiameter.
    34 # Default: 5658. Use 0 to disable.
    35 #SecPort = 5658;
     34# Default: 5868. Use 0 to disable.
     35#SecPort = 5868;
    3636
    3737# Use RFC3588 method for TLS protection, where TLS is negociated after CER/CEA exchange is completed
     
    238238#  No_TCP; No_SCTP; No_IP; No_IPv6; Prefer_TCP; TLS_old_method;
    239239#  No_TLS;       # assume transparent security instead of TLS. DTLS is not supported yet (will change in future versions).
    240 #  Port = 5658;  # The port to connect to
     240#  Port = 5868;  # The port to connect to
    241241#  TcTimer = 30;
    242242#  TwTimer = 30;
  • extensions/app_radgw/md5.c

    r972 r1291  
    293293    byteReverse((unsigned char *) ctx->buf, 4);
    294294    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 */
    296296}
    297297
  • extensions/app_sip/md5.c

    r972 r1291  
    316316    byteReverse((unsigned char *) ctx->buf, 4);
    317317    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 */
    319319}
    320320
  • extensions/dbg_msg_dumps/dbg_msg_dumps.c

    r1306 r1307  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    105105                }
    106106                break;
     107        case HOOK_MESSAGE_PARSING_ERROR2:
     108                LOG_E("PARSING ERROR, returning:");
     109                LOG_SPLIT(FD_LOG_ERROR, "     ", buf, NULL);
     110                break;
    107111        case HOOK_MESSAGE_ROUTING_ERROR:
    108112                LOG_E("ROUTING ERROR '%s' for: ", (char *)other);
     
    117121        case HOOK_MESSAGE_RECEIVED:
    118122                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);
    119127                LOG_SPLIT(FD_LOG_NOTICE, "     ", buf, NULL);
    120128                break;
     
    194202                }
    195203                break;
     204        case HOOK_MESSAGE_PARSING_ERROR2:
     205                LOG_E("PARSING ERROR, returning: %s", buf);
     206                break;
    196207        case HOOK_MESSAGE_ROUTING_ERROR:
    197208                LOG_E("ROUTING ERROR '%s' for: %s", (char *)other, buf);
     
    204215        case HOOK_MESSAGE_RECEIVED:
    205216                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);
    206220                break;
    207221        case HOOK_MESSAGE_SENT:
     
    273287                }
    274288                break;
     289        case HOOK_MESSAGE_PARSING_ERROR2:
     290                LOG_E("PARSING ERROR, returning: %s", buf);
     291                break;
    275292        case HOOK_MESSAGE_ROUTING_ERROR:
    276293                LOG_E("ROUTING ERROR '%s' for: %s", (char *)other, buf);
     
    283300        case HOOK_MESSAGE_RECEIVED:
    284301                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);
    285305                break;
    286306        case HOOK_MESSAGE_SENT:
     
    341361        }
    342362       
    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 */
    345365        mask_routing= HOOK_MASK( HOOK_MESSAGE_LOCAL, HOOK_MESSAGE_ROUTING_FORWARD, HOOK_MESSAGE_ROUTING_LOCAL );
    346366        mask_peers  = HOOK_MASK( HOOK_PEER_CONNECT_FAILED, HOOK_PEER_CONNECT_SUCCESS );
  • extensions/test_app/ta_bench.c

    r1206 r1294  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    3737
    3838#include "test_app.h"
    39 
     39#include <stdio.h>
     40
     41#ifndef __APPLE__ /* they deprecated the semaphore there... */
    4042#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
     56static 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
     63static int my_sem_destroy(my_sem_t *s) {
     64        dispatch_release(*s);
     65        *s = NULL;
     66        return 0;
     67}
     68
     69static 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
     84static int my_sem_post(my_sem_t *s) {
     85        dispatch_semaphore_signal(*s);
     86        return 0;
     87}
     88
     89#endif // APPLE
     90
     91
    4292
    4393struct ta_mess_info {
     
    4696};
    4797
    48 static sem_t ta_sem; /* To handle the concurrency */
     98static my_sem_t ta_sem; /* To handle the concurrency */
    4999
    50100/* Cb called when an answer is received */
     
    110160       
    111161        /* Post the semaphore */
    112         CHECK_SYS_DO( sem_post(&ta_sem), );
     162        CHECK_SYS_DO( my_sem_post(&ta_sem), );
    113163       
    114164        return;
     
    214264        do {
    215265                /* 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);
    217267                if (ret == -1) {
    218268                        ret = errno;
     
    270320int ta_bench_init(void)
    271321{
    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) );
    273323
    274324        CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.bench", ta_bench_start ) );
     
    281331        // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );
    282332       
    283         CHECK_SYS_DO( sem_destroy(&ta_sem), );
     333        CHECK_SYS_DO( my_sem_destroy(&ta_sem), );
    284334       
    285335        return;
  • extensions/test_app/ta_cli.c

    r1214 r1305  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    7171               
    7272                CHECK_FCT_DO( fd_sess_state_retrieve( ta_cli_reg, sess, &mi ), return );
    73                 TRACE_DEBUG( INFO, "%p %p", mi, data);
    7473                ASSERT( (void *)mi == data );
    7574        }
  • freeDiameterd/main.c

    r1182 r1305  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    172172        /* Loop on arguments */
    173173        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);
    175175                if (c == -1)
    176176                        break;  /* Exit from the loop.  */
     
    208208                                #ifdef DEBUG
    209209                                fd_debug_one_function = optarg;
     210                                fd_g_debug_lvl = FD_LOG_DEBUG;
    210211                                #else /* DEBUG */
    211212                                fprintf(stderr, "Error: must compile with DEBUG support to use --dbg_func feature!\n");
     
    217218                                #ifdef DEBUG
    218219                                fd_debug_one_file = basename(optarg);
     220                                fd_g_debug_lvl = FD_LOG_DEBUG;
    219221                                #else /* DEBUG */
    220222                                fprintf(stderr, "Error: must compile with DEBUG support to use --dbg_file feature!\n");
  • include/freeDiameter/CMakeLists.txt

    r1289 r1295  
    1616OPTION(ERRORS_ON_TODO "(development) Generate compilation errors on TODO items ?" OFF)
    1717
    18 # In DEBUG mode, each log contains pid, calling function and file for easy debug. Set to ON to strip this information.
    19 OPTION(DEBUG_WITHOUT_META "Strip calling 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.
     19OPTION(DEBUG_WITH_META "Show calling location in logs?" OFF)
    2020       
    2121# Create the absolute path for searching extensions
     
    3737OPTION(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)
    3838
    39 MARK_AS_ADVANCED(DISABLE_SCTP DEBUG_SCTP SCTP_USE_MAPPED_ADDRESSES ERRORS_ON_TODO DEBUG_WITHOUT_META DIAMID_IDNA_IGNORE DIAMID_IDNA_REJECT DISABLE_PEER_EXPIRY WORKAROUND_ACCEPT_INVALID_VSAI)
     39MARK_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)
    4040
    4141########################
  • include/freeDiameter/freeDiameter-host.h.in

    r1237 r1305  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    5454#cmakedefine DISABLE_SCTP
    5555#cmakedefine DEBUG_SCTP
    56 #cmakedefine DEBUG_WITHOUT_META
     56#cmakedefine DEBUG_WITH_META
    5757#cmakedefine SCTP_USE_MAPPED_ADDRESSES
    5858#cmakedefine SCTP_CONNECTX_4_ARGS
  • include/freeDiameter/libfdcore.h

    r1220 r1305  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2016, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    128128       
    129129        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: 5658) in host byte order */
     130        uint16_t         cnf_port_tls;  /* the local port for Diameter/TLS (default: 5868) in host byte order */
    131131        uint16_t         cnf_port_3436; /* Open an additional server port to listen to old TLS/SCTP clients (RFC3436, freeDiameter versions < 1.2.0) */
    132132        uint16_t         cnf_sctp_str;  /* default max number of streams for SCTP associations (def: 30) */
     
    965965                 */
    966966       
     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       
    967977        HOOK_MESSAGE_SENT,
    968978                /* Hook called when a message has been sent to a peer. The message might be freed as soon as the hook function returns,
     
    9931003                 - {permsgdata} points to existing structure associated with this message (or new structure if no previous hook was registered).
    9941004                 */
    995        
     1005                 
    9961006        HOOK_MESSAGE_ROUTING_ERROR,
    9971007                /* 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).
     
    10491059                 */
    10501060       
    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
    10521071};
    10531072
  • include/freeDiameter/libfdproto.h

    r1281 r1304  
    110110
    111111#define DIAMETER_PORT           3868
    112 #define DIAMETER_SECURE_PORT    5658
     112#define DIAMETER_SECURE_PORT    5868
    113113
    114114
     
    290290#endif /* __PRETTY_FUNCTION__ */
    291291
    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 */
    293293static char * file_bname = NULL;
    294294static char * file_bname_init(char * full) { file_bname = basename(full); return file_bname; }
     
    298298
    299299/* 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))
    301301# define STD_TRACE_FMT_STRING "pid:%s in %s@%s:%d: "
    302302# 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 */
    304304# define STD_TRACE_FMT_STRING ""
    305305# define STD_TRACE_FMT_ARGS
    306 #endif /* DEBUG && !DEBUG_WITHOUT_META */
     306#endif /* DEBUG && DEBUG_WITH_META */
    307307
    308308/*************************
     
    12591259typedef int (*dict_avpdata_encode) (void * data, union avp_value * val);
    12601260
     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 */
     1280typedef int (*dict_avpdata_check) (void * data, union avp_value * val, char ** error_msg);
     1281
     1282
    12611283
    12621284/* Type to hold data associated to a derived AVP data type */
     
    12671289        dict_avpdata_encode      type_encode;   /* cb to convert formatted data into an AVP value (or NULL) */
    12681290        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;
    12691293};
    12701294
     
    12931317DECLARE_FD_DUMP_PROTOTYPE(fd_dictfct_Time_dump, union avp_value * avp_value);
    12941318
     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 */
     1321int fd_dictfct_CharInOS_check(void * data, union avp_value * val, char ** error_msg);
    12951322
    12961323
  • libfdcore/hooks.c

    r1306 r1307  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    345345                        }
    346346                       
     347                        case HOOK_MESSAGE_SENDING: {
     348                                LOG_A("SENDING message to '%s'", peer ? peer->p_hdr.info.pi_diamid : "<unknown>");
     349                                break;
     350                        }
     351                       
    347352                        case HOOK_MESSAGE_SENT: {
    348353                                CHECK_MALLOC_DO(fd_msg_dump_summary(&hook_default_buf, &hook_default_len, NULL, msg, NULL, 0, 1), break);
     
    378383                        }
    379384                       
     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                       
    380393                        case HOOK_MESSAGE_ROUTING_ERROR: {
    381394                                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  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    166166        TRACE_ENTRY("%p %p %p", msg, cnx, peer);
    167167        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));
    168170       
    169171        if (update_reqin_cnt && peer) {
  • libfdcore/routing_dispatch.c

    r1283 r1301  
    454454                        } else {
    455455                                if (!msgptr) {
     456                                        fd_hook_call(HOOK_MESSAGE_PARSING_ERROR2, error, NULL, NULL, fd_msg_pmdl_get(error));
    456457                                        /* error now contains the answer message to send back */
    457458                                        CHECK_FCT( fd_fifo_post(fd_g_outgoing, &error) );
  • libfdproto/dictionary_functions.c

    r1284 r1300  
    359359}
    360360
     361/* Check that a given AVP value contains all the characters from data in the same order */
     362static char error_message[80];
     363int 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  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    9696    /* add timestamp */
    9797    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))
    9999        1, 1
    100 #else /* (defined(DEBUG) && !defined(DEBUG_WITHOUT_META)) */
     100#else /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */
    101101        0, 0
    102 #endif /* (defined(DEBUG) && !defined(DEBUG_WITHOUT_META)) */
     102#endif /* (defined(DEBUG) && defined(DEBUG_WITH_META)) */
    103103            ));
    104104    /* Use colors on stdout ? */
  • libfdproto/messages.c

    r1248 r1305  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2013, WIDE Project and NICT                                                              *
     5* Copyright (c) 2015, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
     
    232232                struct dict_avp_data dictdata;
    233233               
    234                 CHECK_FCT(  fd_dict_getval(model, &dictdata)  );
     234                CHECK_FCT_DO(  fd_dict_getval(model, &dictdata), { free(new); return __ret__; }  );
    235235       
    236236                new->avp_model = model;
     
    248248                new->avp_rawlen = (*avp)->avp_public.avp_len - GETAVPHDRSZ( (*avp)->avp_public.avp_flags );
    249249                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__; }  );
    251251                        memset(new->avp_rawdata, 0x00, new->avp_rawlen);
    252252                }
     
    286286                struct dict_object      *dictappl;
    287287               
    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__; }  );
    290290               
    291291                new->msg_model = model;
     
    294294
    295295                /* 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__; }  );
    297297                if (dictappl != NULL) {
    298298                        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__; }  );
    300300                        new->msg_public.msg_appl = appdata.application_id;
    301301                }
     
    365365               
    366366                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__; } );
    371371                val.os.data = sid;
    372372                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__; } );
    375375                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__; } );
    377377        }
    378378       
     
    383383                struct fd_list avpcpylist = FD_LIST_INITIALIZER(avpcpylist);
    384384               
    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__; } );
    386386                while (avp) {
    387387                        if ( (avp->avp_public.avp_code   == AC_PROXY_INFO)
     
    394394
    395395                                /* 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__; }  );
    399399
    400400                                /* 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__; } );
    402402                               
    403403                                /* 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__; } );
    405405
    406406                                /* Done for this AVP */
     
    411411                        }
    412412                        /* 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__; } );
    414414                }
    415415        }
     
    20372037{
    20382038        struct dict_avp_data dictdata;
     2039        struct dict_type_data derivedtypedata;
     2040        struct dict_object * avp_derived_type = NULL;
    20392041        uint8_t * source;
    20402042       
     
    22172219                        break;
    22182220       
     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                }
    22192248        }
    22202249       
  • tests/testmesg.c

    r1281 r1300  
    309309                        #endif
    310310                }
     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               
    311320                #if 0
    312321                {
     
    753762                                /* reset */
    754763                                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                               
    755806                        }
    756807                       
     
    13991450        }
    14001451       
    1401 
    14021452        /* That's all for the tests yet */
    14031453        PASSTEST();
Note: See TracChangeset for help on using the changeset viewer.