Navigation


Changes in / [949:ad5c976e0dc7:950:51c15f98a965] in freeDiameter


Ignore:
Files:
1 added
21 edited

Legend:

Unmodified
Added
Removed
  • INSTALL.FreeBSD

    r707 r921  
    99
    1010Then 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 ...
    1212
    1313
     
    4646   
    47477) 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 ../freeDiameter
     48   # /usr/local/bin/cmake -DFLEX_EXECUTABLE:FILEPATH=/usr/local/bin/flex -DSCTP_USE_MAPPED_ADDRESSES:BOOL=ON ../freeDiameter
    4949
    50508) Compile, optionnaly test
  • extensions/app_radgw/rgwx_auth.c

    r740 r924  
    458458                if (si_len) {
    459459                        /* 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) );
    461461                } else {
    462462                        /* Create a new Session-Id string */
     
    496496                CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
    497497                CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
     498                CHECK_FCT( fd_msg_sess_set( *diam_fw, *session) );
    498499        }
    499500       
  • extensions/app_radgw/rgwx_sip.c

    r816 r924  
    480480        CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
    481481        CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
     482        CHECK_FCT( fd_msg_sess_set( *diam_fw, *session) );
    482483       
    483484        /*
  • extensions/app_sip/registrationtermination.c

    r706 r924  
    148148        {
    149149                #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) ) );
    159151        }
    160152       
  • extensions/test_app/ta_bench.c

    r879 r924  
    122122        union avp_value val;
    123123        struct ta_mess_info * mi = NULL;
    124         struct session *sess = NULL;
    125124       
    126125        TRACE_DEBUG(FULL, "Creating a new message for sending.");
     
    131130        /* Create a new session */
    132131        #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 );
    134133       
    135134        /* Create the random value to store with the session */
     
    143142       
    144143        /* 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         }
    158144       
    159145        /* Set the Destination-Realm AVP */
  • extensions/test_app/ta_cli.c

    r740 r924  
    151151        /* Create a new session */
    152152        #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 );
    154155       
    155156        /* Create the random value to store with the session */
     
    164165        /* Now set all AVPs values */
    165166       
    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        
    179167        /* Set the Destination-Realm AVP */
    180168        {
  • extensions/test_sip/locationinfo.c

    r706 r924  
    4242        struct msg * message=NULL;
    4343        struct avp *avp=NULL;
    44         struct session *sess=NULL;
    4544        union avp_value value;
    4645       
     
    6261        // Create a new session
    6362        {
    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") ) );
    7364        }
    7465       
  • extensions/test_sip/locationinfosl.c

    r706 r924  
    4242        struct msg * message=NULL;
    4343        struct avp *avp=NULL;
    44         struct session *sess=NULL;
    4544        union avp_value value;
    4645       
     
    6261        // Create a new session
    6362        {
    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") ) );
    7364        }
    7465       
  • extensions/test_sip/serverassignment.c

    r706 r924  
    4242        struct msg * message=NULL;
    4343        struct avp *avp=NULL;
    44         struct session *sess=NULL;
    4544        union avp_value value;
    4645       
     
    7170        // Create a new session
    7271        {
    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") ) );
    8273        }
    8374       
  • extensions/test_sip/userauthorization.c

    r706 r924  
    4242        struct msg * message=NULL;
    4343        struct avp *avp=NULL;
    44         struct session *sess=NULL;
    4544        union avp_value value;
    4645       
     
    6766        // Create a new session
    6867        {
    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") ) );
    7869        }
    7970       
  • include/freeDiameter/libfdproto.h

    r946 r950  
    11581158};
    11591159
     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 */
     1165int fd_dictfct_Address_encode(void * data, union avp_value * avp_value);
     1166int fd_dictfct_Address_interpret(union avp_value * avp_value, void * interpreted);
     1167char * fd_dictfct_Address_dump(union avp_value * avp_value);
     1168
     1169/* Display the content of an AVP of type UTF8String in the log file */
     1170char * fd_dictfct_UTF8String_dump(union avp_value * avp_value);
     1171
     1172/* For Time AVPs, map with time_t value directly */
     1173int fd_dictfct_Time_encode(void * data, union avp_value * avp_value);
     1174int fd_dictfct_Time_interpret(union avp_value * avp_value, void * interpreted);
     1175char * fd_dictfct_Time_dump(union avp_value * avp_value);
     1176
     1177
     1178
     1179/****/
    11601180
    11611181/***
     
    11881208 
    11891209*/
    1190          
     1210
    11911211/*
    11921212 ***************************************************************************
     
    17901810 *
    17911811 * 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.
    17951815 *  ENOMEM      : Not enough memory to complete the operation
    17961816 */
     
    24792499int fd_msg_sess_get(struct dictionary * dict, struct msg * msg, struct session ** session, int * isnew);
    24802500
     2501/* This one is used by the libfdcore, you should use fd_msg_new_session rather than fd_sess_new, when possible */
     2502int fd_msg_sess_set(struct msg * msg, struct session * session);
     2503
     2504
    24812505/***************************************/
    24822506/*   Manage AVP values                 */
  • libfdcore/dict_base_proto.c

    r838 r922  
    4545struct dictionary * fd_g_dict = NULL;
    4646
    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 1024
    151         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 
    21047
    21148
     
    295132                                the content and format of the remaining octets.
    296133                        */
    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 };
    298135                        CHECK_dict_new( DICT_TYPE, &data , NULL, NULL);
    299136                }
     
    314151                                This procedure MUST be supported by all DIAMETER nodes.
    315152                        */
    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            };
    317154                        CHECK_dict_new( DICT_TYPE, &data , NULL, NULL);
    318155                }
     
    352189                                octets, not characters.
    353190                        */
    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    };
    355192                        CHECK_dict_new( DICT_TYPE, &data , NULL, NULL);
    356193                }
     
    381218                                Domain Name (IDNs).
    382219                        */
    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    };
    384221                        CHECK_dict_new( DICT_TYPE, &data , NULL, NULL);
    385222                }
     
    436273                                aaa://host.example.com:1813;transport=udp;protocol=radius
    437274                        */
    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    };
    439276                        CHECK_dict_new( DICT_TYPE, &data , NULL, NULL);
    440277                }
     
    498335                                infrastructure.
    499336                        */
    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    };
    501338                        CHECK_dict_new( DICT_TYPE, &data , NULL, NULL);
    502339                }
  • libfdcore/fdd.l

    r944 r950  
    5252        yylloc->first_column = yylloc->last_column + 1;                 \
    5353        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", \
    5556                yylloc->first_line, yylloc->first_column,               \
    5657                yylloc->last_line, yylloc->last_column,                 \
     
    145146<*>[[:alnum:]]+         |       /* This rule is only useful to print a complete token in error messages */
    146147        /* Unrecognized character */
    147 <*>.                    { 
     148<*>.                    {
    148149                                TRACE_DEBUG_ERROR("Unrecognized text on line %d col %d: '%s'.\n", yylloc->first_line, yylloc->first_column, yytext);
    149150                                return LEX_ERROR;
  • libfdcore/fdd.y

    r944 r950  
    328328                                if (fd == NULL) {
    329329                                        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));
    331331                                        yyerror (&yylloc, conf, "Error adding extension");
    332332                                        YYERROR;
     
    502502                                if (fd == NULL) {
    503503                                        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));
    505505                                        yyerror (&yylloc, conf, "Error on file name");
    506506                                        YYERROR;
     
    510510                                if (fd == NULL) {
    511511                                        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));
    513513                                        yyerror (&yylloc, conf, "Error on file name");
    514514                                        YYERROR;
     
    533533                                if (fd == NULL) {
    534534                                        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));
    536536                                        yyerror (&yylloc, conf, "Error on file name");
    537537                                        YYERROR;
     
    573573                                if (fd == NULL) {
    574574                                        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));
    576576                                        yyerror (&yylloc, conf, "Error on file name");
    577577                                        YYERROR;
     
    616616                                                        &err_pos),
    617617                                                { 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);
    619619                                                  YYERROR; } );
    620620                        }
     
    633633                                if (fd == NULL) {
    634634                                        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));
    636636                                        yyerror (&yylloc, conf, "Error on file name");
    637637                                        YYERROR;
  • libfdcore/messages.c

    r892 r924  
    159159        CHECK_FCT( fd_msg_avp_add( msg, MSG_BRW_FIRST_CHILD, avp ) );
    160160       
     161        /* Save the session associated with the message */
     162        CHECK_FCT( fd_msg_sess_set( msg, sess) );
     163       
    161164        /* Done! */
    162165        return 0;
     
    284287                        hdr->msg_flags |= CMD_FLAG_ERROR;
    285288                else
    286                         hdr->msg_flags &= ! CMD_FLAG_ERROR;
     289                        hdr->msg_flags &= ~ CMD_FLAG_ERROR;
    287290        }
    288291       
  • libfdcore/peers.c

    r947 r950  
    549549        ev_data->validate = !found;
    550550       
    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 );
    552552       
    553553out:   
  • libfdcore/sctp.c

    r946 r950  
    654654                if (ep->sa.sa_family == AF_INET6)
    655655                #else /* SCTP_USE_MAPPED_ADDRESSES */
    656                 if (target_family == AF_INET6) {
     656                if (target_family == AF_INET6)
    657657                #endif /* SCTP_USE_MAPPED_ADDRESSES */
    658658                        sz = sizeof(sSA6);
     
    10871087        /* We will loop while all data is not received. */
    10881088incomplete:
    1089         if (datasize == bufsz - sizeof(struct timespec)) {
     1089        while (datasize + sizeof(struct timespec) >= bufsz ) {
    10901090                /* The buffer is full, enlarge it */
    10911091                bufsz += mempagesz;
  • libfdproto/CMakeLists.txt

    r836 r922  
    66        fdproto-internal.h
    77        dictionary.c
     8        dictionary_functions.c
    89        dispatch.c
    910        fifo.c
  • libfdproto/fdproto-internal.h

    r909 r924  
    7070int fd_sess_reclaim_msg ( struct session ** session );
    7171
     72
    7273/* For dump routines into string buffers */
    7374#include <stdarg.h>
  • libfdproto/messages.c

    r903 r924  
    106106#define _A(_x) ((struct avp *)(_x))
    107107/* 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))
    109109
    110110/* The following structure represents an instance of a message (command and children AVPs). */
     
    239239                if (new->avp_rawlen) {
    240240                        CHECK_MALLOC(  new->avp_rawdata = malloc(new->avp_rawlen)  );
    241                         memset(new->avp_rawdata, 0xFF, new->avp_rawlen);
     241                        memset(new->avp_rawdata, 0x00, new->avp_rawlen);
    242242                }
    243243        }
     
    12161216}
    12171217
     1218/* Associate a session with a message, use only when the session was just created */
     1219int 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
    12181232
    12191233/* Retrieve the session of the message */
     
    12611275       
    12621276        /* 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        }
    12651284       
    12661285        return 0;
     
    16481667                struct avp * avp;
    16491668               
    1650                 if (buflen - offset <= AVPHDRSZ_NOVEND) {
     1669                if (buflen - offset < AVPHDRSZ_NOVEND) {
    16511670                        TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes", buflen - offset);
    16521671                        return EBADMSG;
     
    16661685               
    16671686                if (avp->avp_public.avp_flags & AVP_FLAG_VENDOR) {
    1668                         if (buflen - offset <= 4) {
     1687                        if (buflen - offset < 4) {
    16691688                                TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes for vendor and data", buflen - offset);
    16701689                                free(avp);
     
    16761695               
    16771696                /* 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))) {
    16791699                        TRACE_DEBUG(INFO, "truncated buffer: remaining only %d bytes for data, and avp data size is %d",
    16801700                                        buflen - offset,
  • libfdproto/sessions.c

    r788 r924  
    360360
    361361
    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 */
    363363int fd_sess_new ( struct session ** session, DiamId_t diamid, size_t diamidlen, uint8_t * opt, size_t optlen )
    364364{
     
    461461       
    462462                fd_list_insert_before(li, &sess->chain_h); /* hash table */
     463                sess->msg_cnt++;
    463464        } else {
    464465                free(sid);
     466               
     467                CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) );
     468                (*session)->msg_cnt++;
     469                CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) );
     470               
    465471                /* it was found: was it previously destroyed? */
    466472                if ((*session)->is_destroyed == 0) {
     
    469475                } else {
    470476                        /* 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)");
    472477                        sess = *session;
     478                        sess->is_destroyed = 0;
    473479                       
    474480                        /* update the expiry time */
     
    501507
    502508out:
    503         ;       
     509        ;
    504510        pthread_cleanup_pop(0);
    505511        CHECK_POSIX( pthread_mutex_unlock( H_LOCK(hash) ) );
     
    512518}
    513519
    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 */
     521int fd_sess_fromsid_msg ( uint8_t * sid, size_t len, struct session ** session, int * new)
    516522{
    517523        int ret;
     
    802808
    803809/* For the messages module */
    804 int fd_sess_fromsid_msg ( uint8_t * sid, size_t len, struct session ** session, int * new)
     810int fd_sess_fromsid ( uint8_t * sid, size_t len, struct session ** session, int * new)
    805811{
    806812        TRACE_ENTRY("%p %zd %p %p", sid, len, session, new);
     
    808814       
    809815        /* 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               
    815823        /* Done */
    816824        return 0;
     
    833841{
    834842        int reclaim;
     843        uint32_t hash;
    835844       
    836845        TRACE_ENTRY("%p", session);
    837846        CHECK_PARAMS( session && VALIDATE_SI(*session) );
    838847       
     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
    839853        /* Update the msg refcount */
    840854        CHECK_POSIX( pthread_mutex_lock(&(*session)->stlock) );
     
    843857        CHECK_POSIX( pthread_mutex_unlock(&(*session)->stlock) );
    844858       
     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 */
    845864        if (reclaim == 1) {
    846865                CHECK_FCT(fd_sess_reclaim ( session ));
Note: See TracChangeset for help on using the changeset viewer.