Navigation


Changeset 996:cf09fde3d7f5 in freeDiameter


Ignore:
Timestamp:
Mar 20, 2013, 12:13:14 AM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Children:
997:632913581c37, 998:ad6c1ee04d2d
Phase:
public
Message:

Fix management of sessions in app_radgw: sessions are simply associated with messages, that is sufficient

Location:
extensions/app_radgw
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_radgw/radius.c

    r979 r996  
    5757/*********************************************************************************/
    5858#include "rgw.h"
    59 
    60 /* Overwrite printf */
    61 #define printf(args...) fd_log_debug(args)
    62 
    6359
    6460static struct radius_attr_hdr *
     
    237233}
    238234
    239 
    240 static void print_char(char c)
     235static char print_char_buf[5];
     236
     237static char * print_char(char c)
    241238{
    242239        if (c >= 32 && c < 127)
    243                 printf("%c", c);
     240                sprintf(print_char_buf, "%c", c);
    244241        else
    245                 printf("<%02x>", c);
    246 }
    247 
    248 
    249 static void radius_msg_dump_attr_val(struct radius_attr_hdr *hdr)
     242                sprintf(print_char_buf, "<%02x>", c);
     243        return print_char_buf;
     244}
     245
     246
     247static char * radius_msg_dump_attr_val(struct radius_attr_hdr *hdr, char * outbuf, size_t buflen)
    250248{
    251249        struct radius_attr_type *attr;
     
    253251        unsigned char *pos;
    254252        u8 attrtype;
     253        size_t offset = 0;
     254       
     255        memset(outbuf, 0, buflen);
    255256
    256257        attr = radius_get_attr_type(hdr->type);
     
    266267        switch (attrtype) {
    267268        case RADIUS_ATTR_TEXT:
    268                 printf("      Value: '");
     269                snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value: '");
    269270                for (i = 0; i < len; i++)
    270                         print_char(pos[i]);
    271                 printf("'\n");
     271                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "%s", print_char(pos[i]));
     272                snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "'");
    272273                break;
    273274
     
    276277                        struct in_addr addr;
    277278                        os_memcpy(&addr, pos, 4);
    278                         printf("      Value: %s\n", inet_ntoa(addr));
     279                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value: %s", inet_ntoa(addr));
    279280                } else
    280                         printf("      Invalid IP address length %d\n", len);
     281                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Invalid IP address length %d", len);
    281282                break;
    282283
     
    287288                        struct in6_addr *addr = (struct in6_addr *) pos;
    288289                        atxt = inet_ntop(AF_INET6, addr, buf, sizeof(buf));
    289                         printf("      Value: %s\n", atxt ? atxt : "?");
     290                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value: %s", atxt ? atxt : "?");
    290291                } else
    291                         printf("      Invalid IPv6 address length %d\n", len);
     292                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Invalid IPv6 address length %d", len);
    292293                break;
    293294
    294295        case RADIUS_ATTR_INT32:
    295296                if (len == 4)
    296                         printf("      Value: %u\n", WPA_GET_BE32(pos));
     297                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value: %u", WPA_GET_BE32(pos));
    297298                else
    298                         printf("      Invalid INT32 length %d\n", len);
     299                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Invalid INT32 length %d", len);
    299300                break;
    300301
     
    302303        case RADIUS_ATTR_UNDIST:
    303304        default:
    304                 printf("      Value:");
     305                snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value:");
    305306                for (i = 0; i < len; i++)
    306                         printf(" %02x", pos[i]);
    307                 printf("\n");
     307                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " %02x", pos[i]);
    308308                break;
    309309        }
     310       
     311        return outbuf;
    310312}
    311313
     
    314316{
    315317        unsigned char *auth;
     318        char buf[256];
    316319        size_t i;
    317320        if (! TRACE_BOOL(FULL) )
     
    329332                struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]);
    330333                fd_log_debug("    - Type: 0x%02hhx (%s)       Len: %-3hhu", attr->type, rgw_msg_attrtype_str(attr->type), attr->length);
    331                 radius_msg_dump_attr_val(attr);
     334                fd_log_debug("%s", radius_msg_dump_attr_val(attr, buf, sizeof(buf)));
    332335        }
    333336        if (has_meta && msg->ps_nb) {
     
    336339                        struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]);
    337340                        fd_log_debug("    - Type: 0x%02hhx (%s)       Len: %-3hhu", attr->type, rgw_msg_attrtype_str(attr->type), attr->length);
    338                         radius_msg_dump_attr_val(attr);
     341                        fd_log_debug("%s", radius_msg_dump_attr_val(attr, buf, sizeof(buf)));
    339342                }
    340343        }
     
    355358                                           auth, MD5_MAC_LEN);
    356359                if (attr == NULL) {
    357                         printf("WARNING: Could not add Message-Authenticator\n");
     360                        fd_log_debug("WARNING: Could not add Message-Authenticator");
    358361                        return -1;
    359362                }
     
    365368
    366369        if (msg->buf_used > 0xffff) {
    367                 printf("WARNING: too long RADIUS message (%lu)\n",
     370                fd_log_debug("WARNING: too long RADIUS message (%lu)",
    368371                       (unsigned long) msg->buf_used);
    369372                return -1;
     
    386389                                       auth, MD5_MAC_LEN);
    387390            if (attr == NULL) {
    388                     printf("WARNING: Could not add Message-Authenticator\n");
     391                    fd_log_debug("WARNING: Could not add Message-Authenticator");
    389392                    return -1;
    390393            }
     
    410413
    411414        if (msg->buf_used > 0xffff) {
    412                 printf("WARNING: too long RADIUS message (%lu)\n",
     415                fd_log_debug("WARNING: too long RADIUS message (%lu)",
    413416                       (unsigned long) msg->buf_used);
    414417                return -1;
     
    433436
    434437        if (msg->buf_used > 0xffff) {
    435                 printf("WARNING: too long RADIUS messages (%lu)\n",
     438                fd_log_debug("WARNING: too long RADIUS messages (%lu)",
    436439                       (unsigned long) msg->buf_used);
    437440        }
     
    468471
    469472        if (data_len > RADIUS_MAX_ATTR_LEN) {
    470                 printf("radius_msg_add_attr: too long attribute (%lu bytes)\n",
     473                fd_log_debug("radius_msg_add_attr: too long attribute (%lu bytes)",
    471474                       (unsigned long) data_len);
    472475                return NULL;
     
    692695                if (tmp->type == RADIUS_ATTR_MESSAGE_AUTHENTICATOR) {
    693696                        if (attr != NULL) {
    694                                 printf("Multiple Message-Authenticator attributes in RADIUS message\n");
     697                                fd_log_debug("Multiple Message-Authenticator attributes in RADIUS message");
    695698                                return 1;
    696699                        }
     
    700703
    701704        if (attr == NULL) {
    702                 printf("No Message-Authenticator attribute found\n");
     705                fd_log_debug("No Message-Authenticator attribute found");
    703706                return 1;
    704707        }
     
    720723
    721724        if (os_memcmp(orig, auth, MD5_MAC_LEN) != 0) {
    722                 printf("Invalid Message-Authenticator!\n");
     725                fd_log_debug("Invalid Message-Authenticator!");
    723726                return 1;
    724727        }
     
    736739
    737740        if (sent_msg == NULL) {
    738                 printf("No matching Access-Request message found\n");
     741                fd_log_debug("No matching Access-Request message found");
    739742                return 1;
    740743        }
     
    757760        md5_vector(4, addr, len, hash);
    758761        if (os_memcmp(hash, msg->hdr->authenticator, MD5_MAC_LEN) != 0) {
    759                 printf("Response Authenticator invalid!\n");
     762                fd_log_debug("Response Authenticator invalid!");
    760763                return 1;
    761764        }
     
    895898        left = len - 2;
    896899        if (left % 16) {
    897                 printf("Invalid ms key len %lu\n", (unsigned long) left);
     900                fd_log_debug("Invalid ms key len %lu", (unsigned long) left);
    898901                return NULL;
    899902        }
     
    929932
    930933        if (plain[0] == 0 || plain[0] > plen - 1) {
    931                 printf("Failed to decrypt MPPE key\n");
     934                fd_log_debug("Failed to decrypt MPPE key");
    932935                os_free(plain);
    933936                return NULL;
  • extensions/app_radgw/rgw.h

    r741 r996  
    116116void rgw_plg_dump(void);
    117117void rgw_plg_start_cache(void);
    118 int rgw_plg_loop_req(struct rgw_radius_msg_meta **rad, struct session **session, struct msg **diam_msg, struct rgw_client * cli);
    119 int rgw_plg_loop_ans(struct rgw_radius_msg_meta *req, struct session *session, struct msg **diam_ans, struct radius_msg ** rad_ans, struct rgw_client * cli, int * stateful);
     118int rgw_plg_loop_req(struct rgw_radius_msg_meta **rad, struct msg **diam_msg, struct rgw_client * cli);
     119int rgw_plg_loop_ans(struct rgw_radius_msg_meta *req, struct msg **diam_ans, struct radius_msg ** rad_ans, struct rgw_client * cli);
    120120void rgw_plg_fini(void);
    121121
  • extensions/app_radgw/rgw_common.h

    r740 r996  
    7474
    7575        /* handle an incoming RADIUS message */
    76         int     (*rgwp_rad_req) ( struct rgwp_config * conf, struct session ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli );
     76        int     (*rgwp_rad_req) ( struct rgwp_config * conf, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli );
    7777        /* ret >0: critical error (errno), log and exit.
    7878           ret 0: continue;
     
    8282       
    8383        /* handle the corresponding Diameter answer */
    84         int     (*rgwp_diam_ans) ( struct rgwp_config * conf, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful );
     84        int     (*rgwp_diam_ans) ( struct rgwp_config * conf, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli );
    8585        /* ret 0: continue; ret >0: error; ret: -1 ... (tbd) */
    86         /* if *stateful = 1 on return, the session will not be destroyed after RADIUS answer is sent. The extension must ensure to register a timeout on the session in this case. */
    8786       
    8887} rgwp_descriptor;
  • extensions/app_radgw/rgw_plugins.c

    r974 r996  
    328328}
    329329
    330 int rgw_plg_loop_req(struct rgw_radius_msg_meta **rad, struct session **session, struct msg **diam_msg, struct rgw_client * cli)
     330int rgw_plg_loop_req(struct rgw_radius_msg_meta **rad, struct msg **diam_msg, struct rgw_client * cli)
    331331{
    332332        int ret = 0;
     
    334334        struct radius_msg * rad_ans = NULL;
    335335       
    336         TRACE_ENTRY("%p %p %p %p", rad, session, diam_msg, cli);
    337         CHECK_PARAMS( rad && *rad && session && diam_msg && *diam_msg && cli);
     336        TRACE_ENTRY("%p %p %p", rad, diam_msg, cli);
     337        CHECK_PARAMS( rad && *rad && diam_msg && *diam_msg && cli);
    338338       
    339339        /* First, get the list of extensions for this message */
     
    348348                if (plg->descriptor->rgwp_rad_req) {
    349349                        TRACE_DEBUG(ANNOYING, "Calling next plugin: %s", plg->descriptor->rgwp_name);
    350                         ret = (*plg->descriptor->rgwp_rad_req)(plg->cs, session, &(*rad)->radius, &rad_ans, diam_msg, cli);
     350                        ret = (*plg->descriptor->rgwp_rad_req)(plg->cs, &(*rad)->radius, &rad_ans, diam_msg, cli);
    351351                        if (ret)
    352352                                break;
     
    368368        }
    369369       
    370         /* Destroy the session, there won't be a reply message to retrieve the data */
    371         if (*session) {
    372                 CHECK_FCT_DO( fd_sess_destroy(session), );
    373         }
    374        
    375370        /* Send the radius message back if required */
    376371        if ((ret == -2) && rad_ans && rad) {
     
    390385
    391386/* Loop in the extension list (same as req) to convert data from diam_ans to rad_ans */
    392 int rgw_plg_loop_ans(struct rgw_radius_msg_meta *req, struct session *session, struct msg **diam_ans, struct radius_msg ** rad_ans, struct rgw_client * cli, int * stateful)
     387int rgw_plg_loop_ans(struct rgw_radius_msg_meta *req, struct msg **diam_ans, struct radius_msg ** rad_ans, struct rgw_client * cli)
    393388{
    394389        int ret = 0;
    395390        struct fd_list * head = NULL, *li;
    396391       
    397         TRACE_ENTRY("%p %p %p %p %p %p", req, session, diam_ans, rad_ans, cli, stateful);
    398         CHECK_PARAMS( req && session && diam_ans && *diam_ans && rad_ans && *rad_ans && cli && stateful);
    399        
    400         *stateful = 0; /* default: stateless gateway */
     392        TRACE_ENTRY("%p %p %p %p", req, diam_ans, rad_ans, cli);
     393        CHECK_PARAMS( req && diam_ans && *diam_ans && rad_ans && *rad_ans && cli);
    401394       
    402395        /* Get the list of extensions of the RADIUS request */
     
    412405                if (plg->descriptor->rgwp_diam_ans) {
    413406                        TRACE_DEBUG(ANNOYING, "Calling next plugin: %s", plg->descriptor->rgwp_name);
    414                         ret = (*plg->descriptor->rgwp_diam_ans)(plg->cs, session, diam_ans, rad_ans, (void *)cli, &locstateful);
     407                        ret = (*plg->descriptor->rgwp_diam_ans)(plg->cs, diam_ans, rad_ans, (void *)cli);
    415408                        if (ret)
    416409                                break;
    417                         *stateful |= locstateful;
    418410                } else {
    419411                        TRACE_DEBUG(ANNOYING, "Skipping extension '%s' (NULL callback)", plg->descriptor->rgwp_name);
  • extensions/app_radgw/rgw_servers.c

    r974 r996  
    133133                }
    134134               
    135                 TRACE_DEBUG(FULL, "Received %d bytes", len);
    136                 TRACE_sSA(FD_LOG_DEBUG, FULL, " from ", &from, NI_NUMERICHOST | NI_NUMERICSERV, "" );
     135                {
     136                        char __buf[1024];
     137                        sSA_DUMP_NODE_SERV(__buf, sizeof(__buf), &from, NI_NUMERICHOST | NI_NUMERICSERV );
     138                        TRACE_DEBUG(FULL, "Received %d bytes from %s", len, __buf);
     139                }
    137140               
    138141                /* Search the associated client definition, if any */
     
    273276        }
    274277       
    275         TRACE_DEBUG(FULL, "Sending %d bytes", buflen);
    276         TRACE_sSA(FD_LOG_DEBUG, FULL, " to ", &sto, NI_NUMERICHOST | NI_NUMERICSERV, "" );
     278        {
     279                char __buf[1024];
     280                sSA_DUMP_NODE_SERV(__buf, sizeof(__buf), &sto, NI_NUMERICHOST | NI_NUMERICSERV );
     281                TRACE_DEBUG(FULL, "Sending %d bytes to %s", buflen, __buf);
     282        }
    277283               
    278284        /* Send */
  • extensions/app_radgw/rgw_worker.c

    r979 r996  
    5454        struct rgw_radius_msg_meta * rad;  /* the RADIUS message that was received and translated */
    5555        struct rgw_client          * cli;  /* the client it was received from */
    56         struct session             * sess; /* the Diameter session created for this message (useful?) */
    5756};
    5857
     
    7675                struct rgw_radius_msg_meta * msg;
    7776                struct rgw_client * cli;
    78                 struct session * session;
    7977                struct msg * diam_msg;
    8078                int pb, a;
     
    133131                        }  );
    134132               
    135                 session = NULL;
    136                
    137133                /* Pass the message to the list of registered plugins */
    138                 CHECK_FCT_DO( rgw_plg_loop_req(&msg, &session, &diam_msg, cli),
     134                CHECK_FCT_DO( rgw_plg_loop_req(&msg, &diam_msg, cli),
    139135                        {
    140136                                /* An error occurred, discard message */
     
    142138                                        CHECK_FCT_DO( fd_msg_free(diam_msg), );
    143139                                        diam_msg = NULL;
    144                                 }
    145                                 if (session) {
    146                                         CHECK_FCT_DO( fd_sess_destroy(&session), );
    147140                                }
    148141                                rgw_msg_free(&msg);
     
    181174                if (pb) {
    182175                        /* Something went wrong during the conversion */
    183                         if (session) {
    184                                 CHECK_FCT_DO( fd_sess_destroy(&session), );
    185                         }
    186                        
    187176                        if (diam_msg) {
    188177                                CHECK_FCT_DO( fd_msg_free(diam_msg), );
     
    202191                pa->rad = msg;
    203192                pa->cli = cli;
    204                 pa->sess= session;
    205193               
    206194                CHECK_FCT_DO( fd_msg_send( &diam_msg, receive_diam_answer, pa),
     
    208196                                /* If an error occurs, log and destroy the data */
    209197                                fd_log_debug("An error occurred while sending Diameter message, please turn Debug on for detail.");
    210                                 if (session) {
    211                                         CHECK_FCT_DO( fd_sess_destroy(&session), );
    212                                 }
    213198
    214199                                if (diam_msg) {
     
    239224        struct avp_hdr  *ahdr;
    240225        int pb = 0;
    241         int keepsession=0;
    242226       
    243227        TRACE_ENTRY("%p %p", pa, ans);
     
    248232       
    249233        /* Pass the Diameter answer to the same extensions as the request */
    250         CHECK_FCT_DO( rgw_plg_loop_ans(pa->rad, pa->sess, ans, &rad_ans, pa->cli, &keepsession), goto out );
     234        CHECK_FCT_DO( rgw_plg_loop_ans(pa->rad, ans, &rad_ans, pa->cli), goto out );
    251235
    252236        if (*ans != NULL) {
     
    300284        }
    301285       
    302         if (!keepsession) {
    303                 /* Destroy remaining session data (stateless gateway) */
    304                 CHECK_FCT_DO( fd_sess_destroy(&pa->sess),  );
    305         }
    306        
    307286        /* Clear the RADIUS request */
    308287        if (pa->rad) {
  • extensions/app_radgw/rgwx_acct.c

    r974 r996  
    289289
    290290/* Incoming RADIUS request */
    291 static int acct_rad_req( struct rgwp_config * cs, struct session ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
     291static int acct_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
    292292{
    293293        int idx;
     
    303303        union avp_value value;
    304304        struct avp ** avp_tun = NULL, *avp = NULL;
     305        struct session * sess;
    305306       
    306307        const char * prefix = "Diameter/";
     
    311312        size_t un_len = 0;
    312313       
    313         TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
     314        TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli);
    314315        CHECK_PARAMS(rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCOUNTING_REQUEST) && rad_ans && diam_fw && *diam_fw);
    315316       
     
    452453        if (status_type == RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_OFF) {
    453454                TRACE_DEBUG(FULL, "[acct.rgwx] Received Accounting-Off Acct-Status-Type attribute, we must terminate all active sessions.");
    454                 TODO("RADIUS side is rebooting, send STR on all sessions?");
     455                TODO("RADIUS side is rebooting, send STR on all sessions???");
    455456                return ENOTSUP;
    456457        }
    457458       
    458459        /* Check if we got a valid session information, otherwise the server will not be able to handle the data... */
    459         if (!*session && !si) {
     460        if (!si) {
    460461                TRACE_DEBUG(INFO, "[acct.rgwx] RADIUS Account-Request from %s did not contain a CLASS attribute with Diameter session information, reject.", rgw_clients_id(cli));
    461462                return EINVAL;
     
    483484        }
    484485        CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
    485         CHECK_FCT( fd_msg_avp_add ( *diam_fw, *session ? MSG_BRW_LAST_CHILD : MSG_BRW_FIRST_CHILD, avp) );
    486        
    487         /* Create the Session-Id AVP if needed */
    488         if (!*session) {
    489                 CHECK_FCT( fd_sess_fromsid ( si, si_len, session, NULL) );
     486        CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
     487       
     488        /* Create the Session-Id AVP */
     489        {
     490                CHECK_FCT( fd_sess_fromsid_msg ( si, si_len, &sess, NULL) );
    490491               
    491492                TRACE_DEBUG(FULL, "[acct.rgwx] Translating new accounting message for session '%.*s'...", si_len, si);
     
    497498                CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
    498499                CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
     500                CHECK_FCT( fd_msg_sess_set(*diam_fw, sess) );
    499501        }
    500502       
     
    11771179        {
    11781180                struct sess_state * st;
    1179                 CHECK_PARAMS(session);
    11801181               
    11811182                CHECK_MALLOC( st = malloc(sizeof(struct sess_state)) );
     
    11861187                }
    11871188                st->term_cause = str_cause;
    1188                 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &st ) );
     1189                CHECK_FCT( fd_sess_state_store( cs->sess_hdl, sess, &st ) );
    11891190        }
    11901191       
     
    12221223}
    12231224
    1224 static int acct_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful )
     1225static int acct_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli )
    12251226{
     1227        struct session * sess;
    12261228        struct sess_state * st = NULL, stloc;
    12271229        struct avp *avp, *next;
    1228         struct avp_hdr *ahdr, *sid, *oh, *or;
    1229        
    1230         TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli);
     1230        struct avp_hdr *ahdr, *oh, *or;
     1231        os0_t sid = NULL;
     1232        size_t sidlen;
     1233       
     1234        TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli);
    12311235        CHECK_PARAMS(cs);
    12321236       
    1233         if (session) {
    1234                 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, session, &st ) );
     1237        CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_ans, &sess, NULL) );
     1238        if (sess) {
     1239                CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess, &st ) );
     1240                CHECK_FCT( fd_sess_getsid(sess, &sid, &sidlen) );
    12351241        }
    12361242       
     
    12461252       
    12471253        /* Search these AVPs first */
    1248         CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Session_Id, &avp) );
    1249         CHECK_FCT( fd_msg_avp_hdr ( avp, &sid ) );
    1250        
    12511254        CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Origin_Host, &avp) );
    12521255        CHECK_FCT( fd_msg_avp_hdr ( avp, &oh ) );
     
    12691272                                        ahdr->avp_value->u32,
    12701273                                        oh->avp_value->os.len, oh->avp_value->os.data,
    1271                                         sid->avp_value->os.len, sid->avp_value->os.data);
     1274                                        sidlen, sid);
    12721275                        CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Error_Message, &avp) );
    12731276                        if (avp) {
     
    13101313                CHECK_FCT(  fd_msg_new ( cs->dict.Session_Termination_Request, MSGFL_ALLOC_ETEID, &str )  );
    13111314               
    1312                 /* Set the application-id to the auth application if available, accouting otherwise (not sure what is actually expected...) */
     1315                /* Set the application-id to the auth application if available, accounting otherwise (not sure what is actually expected...) */
    13131316                CHECK_FCT( fd_msg_hdr ( str, &hdr ) );
    13141317                hdr->msg_appl = st->auth_appl ?: AI_ACCT;
     
    13161319                /* Add the Session-Id AVP as first AVP */
    13171320                CHECK_FCT( fd_msg_avp_new (  cs->dict.Session_Id, 0, &avp ) );
    1318                 CHECK_FCT( fd_msg_avp_setvalue ( avp, sid->avp_value ) );
     1321                avp_val.os.data = sid;
     1322                avp_val.os.len = sidlen;
     1323                CHECK_FCT( fd_msg_avp_setvalue ( avp, &avp_val ) );
    13191324                CHECK_FCT( fd_msg_avp_add ( str, MSG_BRW_FIRST_CHILD, avp) );
     1325                CHECK_FCT( fd_sess_ref_msg(sess) );
    13201326
    13211327                /* Add the Destination-Realm as next AVP */
  • extensions/app_radgw/rgwx_auth.c

    r979 r996  
    229229
    230230/* Handle an incoming RADIUS request */
    231 static int auth_rad_req( struct rgwp_config * cs, struct session ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
     231static int auth_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
    232232{
    233233        int idx;
     
    250250        struct avp ** avp_tun = NULL, *avp = NULL;
    251251        union avp_value value;
    252        
    253         TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
    254         CHECK_PARAMS(cs && session && rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw);
     252        struct session * sess;
     253       
     254        TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli);
     255        CHECK_PARAMS(cs && rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw);
    255256       
    256257        pref_len = strlen(prefix);
     
    440441        }
    441442        CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
    442         CHECK_FCT( fd_msg_avp_add ( *diam_fw, *session ? MSG_BRW_LAST_CHILD : MSG_BRW_FIRST_CHILD, avp) );
     443        CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
    443444       
    444445        /* Add the Destination-Host if found */
     
    448449                value.os.len = dh_len;
    449450                CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
    450                 CHECK_FCT( fd_msg_avp_add ( *diam_fw, *session ? MSG_BRW_LAST_CHILD : MSG_BRW_FIRST_CHILD, avp) );
     451                CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
    451452        }
    452453       
    453454        /* Create the session if it is not already done */
    454         if (*session == NULL) {
     455        {
    455456                os0_t sess_str = NULL;
    456457                size_t sess_strlen;
     
    458459                if (si_len) {
    459460                        /* We already have the Session-Id, just use it */
    460                         CHECK_FCT( fd_sess_fromsid_msg ( si, si_len, session, NULL) );
     461                        CHECK_FCT( fd_sess_fromsid_msg ( si, si_len, &sess, NULL) );
    461462                } else {
    462463                        /* Create a new Session-Id string */
     
    476477                                CHECK_MALLOC( sess_str = malloc(un_len + 1 /* ';' */ + fd_g_config->cnf_diamid_len + 1 /* '\0' */) );
    477478                                len = sprintf((char *)sess_str, "%.*s;%s", (int)un_len, un, fd_g_config->cnf_diamid);
    478                                 CHECK_FCT( fd_sess_new(session, fqdn, fqdnlen, sess_str, len) );
     479                                CHECK_FCT( fd_sess_new(&sess, fqdn, fqdnlen, sess_str, len) );
    479480                                free(sess_str);
    480481                        } else {
     
    486487               
    487488                /* Now, add the Session-Id AVP at beginning of Diameter message */
    488                 CHECK_FCT( fd_sess_getsid(*session, &sess_str, &sess_strlen) );
    489                
     489                CHECK_FCT( fd_sess_getsid(sess, &sess_str, &sess_strlen) );
    490490                TRACE_DEBUG(FULL, "[auth.rgwx] Translating new message for session '%s'...", sess_str);
    491491               
    492                 /* Add the Session-Id AVP as first AVP */
     492                /* Now add this session in the message */
    493493                CHECK_FCT( fd_msg_avp_new ( cs->dict.Session_Id, 0, &avp ) );
    494494                value.os.data = sess_str;
     
    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) );
     498                CHECK_FCT( fd_msg_sess_set(*diam_fw, sess) );
    499499        }
    500500       
     
    10561056
    10571057        /* Store the request identifier in the session (if provided) */
    1058         if (*session) {
     1058        {
    10591059                unsigned char * req_auth;
    10601060                CHECK_MALLOC(req_auth = malloc(16));
    10611061                memcpy(req_auth, &rad_req->hdr->authenticator[0], 16);
    10621062               
    1063                 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &req_auth ) );
     1063                CHECK_FCT( fd_sess_state_store( cs->sess_hdl, sess, &req_auth ) );
    10641064        }
    10651065       
     
    10671067}
    10681068
    1069 static int auth_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful )
     1069static int auth_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli )
    10701070{
    10711071        struct msg_hdr * hdr;
    1072         struct avp *avp, *next, *avp_x, *avp_y, *asid, *aoh;
    1073         struct avp_hdr *ahdr, *sid, *oh;
     1072        struct avp *avp, *next, *avp_x, *avp_y, *aoh;
     1073        struct avp_hdr *ahdr, *oh;
    10741074        uint8_t buf[254]; /* to store some attributes values (with final '\0') */
    10751075        size_t sz;
     
    10791079        unsigned char * req_auth = NULL;
    10801080        int error_cause = 0;
    1081        
    1082         TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli);
    1083         CHECK_PARAMS(cs && session && diam_ans && *diam_ans && rad_fw && *rad_fw);
     1081        struct session * sess;
     1082        os0_t sid = NULL;
     1083        size_t sidlen;
     1084       
     1085        TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli);
     1086        CHECK_PARAMS(cs && diam_ans && *diam_ans && rad_fw && *rad_fw);
    10841087       
    10851088        /* Retrieve the request identified which was stored in the session */
    1086         if (session) {
    1087                 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, session, &req_auth ) );
    1088         }
     1089        CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_ans, &sess, NULL) );
     1090        if (sess) {
     1091                CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess, &req_auth ) );
     1092                CHECK_FCT( fd_sess_getsid(sess, &sid, &sidlen) );
     1093        } /* else ? */
    10891094       
    10901095        /*     
     
    11451150
    11461151        /* Search the different AVPs we handle here */
    1147         CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Session_Id, &asid) );
    1148         CHECK_FCT( fd_msg_avp_hdr ( asid, &sid ) );
    11491152        CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Origin_Host, &aoh) );
    11501153        CHECK_FCT( fd_msg_avp_hdr ( aoh, &oh ) );
     
    12401243                                        ahdr->avp_value->u32,
    12411244                                        oh->avp_value->os.len, oh->avp_value->os.data,
    1242                                         sid->avp_value->os.len, sid->avp_value->os.data);
     1245                                        sidlen, sid);
    12431246                        CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Error_Message, &avp_x) );
    12441247                        if (avp_x) {
     
    12711274                                (int)oh->avp_value->os.len,  (char *)oh->avp_value->os.data,
    12721275                                (int)ahdr->avp_value->os.len,  (char *)ahdr->avp_value->os.data,
    1273                                 (int)sid->avp_value->os.len, (char *)sid->avp_value->os.data))) {
     1276                                (int)sidlen, (char *)sid))) {
    12741277                        TRACE_DEBUG(INFO, "Data truncated in State attribute: %s", buf);
    12751278                }
     
    12801283                /* Add the Session-Id */
    12811284                if (sizeof(buf) < (sz = snprintf((char *)buf, sizeof(buf), "Diameter/%.*s",
    1282                                 (int)sid->avp_value->os.len, sid->avp_value->os.data))) {
     1285                                (int)sidlen, sid))) {
    12831286                        TRACE_DEBUG(INFO, "Data truncated in Class attribute: %s", buf);
    12841287                }
     
    14551458                                                                        ((ahdr->avp_value->u32 == 2) ? "AUTHORIZE_ONLY" : "???"),
    14561459                                                                oh->avp_value->os.len, oh->avp_value->os.data,
    1457                                                                 sid->avp_value->os.len, sid->avp_value->os.len);
     1460                                                                sidlen, sid);
    14581461                                        }
    14591462                                        break;
     
    16161619                                        fd_log_debug("[auth.rgwx] Received Diameter answer with non-translatable NAS-Filter-Rule AVP from '%.*s' (session: '%.*s'), ignoring.",
    16171620                                                        oh->avp_value->os.len, oh->avp_value->os.data,
    1618                                                         sid->avp_value->os.len, sid->avp_value->os.data);
     1621                                                        sidlen, sid);
    16191622                                        handled = 0;
    16201623                                        break;
     
    16491652                                        fd_log_debug("[auth.rgwx] Received Diameter answer with non-translatable QoS-Filter-Rule AVP from '%.*s' (session: '%.*s'), ignoring.",
    16501653                                                        oh->avp_value->os.len, oh->avp_value->os.data,
    1651                                                         sid->avp_value->os.len, sid->avp_value->os.data);
     1654                                                        sidlen, sid);
    16521655                                        handled = 0;
    16531656                                        break;
     
    19211924        }
    19221925       
    1923         CHECK_FCT( fd_msg_free( asid ) );
    19241926        CHECK_FCT( fd_msg_free( aoh ) );
    19251927        free(req_auth);
     
    19301932                        return ENOMEM;
    19311933                }
    1932         }               
     1934        }
    19331935
    19341936        if ((*rad_fw)->hdr->code == RADIUS_CODE_ACCESS_ACCEPT) {
  • extensions/app_radgw/rgwx_debug.c

    r974 r996  
    7272
    7373/* Function called when a new RADIUS message is being converted to Diameter */
    74 static int debug_rad_req( struct rgwp_config * cs, struct session ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
     74static int debug_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
    7575{
    76         TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
     76        TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli);
    7777       
    7878        fd_log_debug("------------- RADIUS/Diameter Request Debug%s%s%s -------------", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : "");
     
    9999        }
    100100       
    101         if (!session || ! *session) {
    102                 fd_log_debug(" Diameter session: NULL pointer");
    103         } else {
    104                 os0_t str;
    105                 size_t str_len;
    106                 CHECK_FCT( fd_sess_getsid(*session, &str, &str_len) );
    107 
    108                 fd_log_debug(" Diameter session: %s", str);
    109         }
    110        
    111101        fd_log_debug("===========  Debug%s%s%s complete =============", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : "");
    112102       
     
    115105
    116106/* This one, when Diameter answer is converted to RADIUS */
    117 static int debug_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful )
     107static int debug_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli )
    118108{
    119         TRACE_ENTRY("%p %p %p %p %p %p", cs, session, diam_ans, rad_fw, cli, stateful);
     109        TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli);
    120110
    121111        fd_log_debug("------------- RADIUS/Diameter Answer Debug%s%s%s -------------", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : "");
  • extensions/app_radgw/rgwx_echodrop.c

    r979 r996  
    119119
    120120/* Handle attributes from a RADIUS request as specified in the configuration */
    121 static int ed_rad_req( struct rgwp_config * cs, struct session ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
     121static int ed_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
    122122{
    123123        size_t nattr_used = 0;
    124124        int idx;
    125        
    126125        struct fd_list echo_list = FD_LIST_INITIALIZER(echo_list);
    127126        struct fd_list *li;
    128127       
    129         TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
    130         CHECK_PARAMS(cs && rad_req && session);
     128        TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli);
     129        CHECK_PARAMS(cs && rad_req);
    131130       
    132131        /* For each attribute in the original message */
     
    217216        /* Save the echoed values in the session, if any */
    218217        if (!FD_IS_LIST_EMPTY(&echo_list)) {
    219                 CHECK_PARAMS_DO(*session,
     218                struct session * sess;
     219               
     220                CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_fw, &sess, NULL) );
     221
     222                CHECK_PARAMS_DO(sess,
    220223                        {
    221224                                fd_log_debug(   "[echodrop.rgwx] The extension is configured to echo some attributes from this message, but no session object has been created for it (yet)."
     
    231234               
    232235                /* Save the list in the session */
    233                 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &li ) );
     236                CHECK_FCT( fd_sess_state_store( cs->sess_hdl, sess, &li ) );
    234237        }
    235238       
     
    238241
    239242/* Process an answer: add the ECHO attributes back, if any */
    240 static int ed_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful )
     243static int ed_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli )
    241244{
    242245        struct fd_list * list = NULL;
    243        
    244         TRACE_ENTRY("%p %p %p %p %p %p", cs, session, diam_ans, rad_fw, cli, stateful);
     246        struct session * sess;
     247       
     248        TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli);
    245249        CHECK_PARAMS(cs);
    246250       
     251        CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_ans, &sess, NULL) );
     252       
    247253        /* If there is no session associated, just give up */
    248         if (! session ) {
     254        if (! sess ) {
    249255                TRACE_DEBUG(FULL, "No session associated with the message, nothing to do here...");
    250256                return 0;
     
    252258       
    253259        /* Now try and retrieve any data from the session */
    254         CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, session, &list ) );
     260        CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess, &list ) );
    255261        if (list == NULL) {
    256262                /* No attribute saved in the session, just return */
  • extensions/app_radgw/rgwx_sample.c

    r741 r996  
    7070
    7171/* This function is called on incoming RADIUS messages. It should handle (some) RADIUS data and store into the Diameter message. */
    72 static int sample_rad_req( struct rgwp_config * cs, struct session ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
     72static int sample_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
    7373{
    74         TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
     74        TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli);
    7575        CHECK_PARAMS(cs);
    7676        TRACE_DEBUG(INFO, "RADIUS/Diameter Sample plugin received a new RADIUS message.");
     
    7979
    8080/* This function is called when a Diameter answer is coming back. It should remove the AVPs and add the attributes in the RADIUS message. */
    81 static int sample_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful )
     81static int sample_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli )
    8282{
    83         TRACE_ENTRY("%p %p %p %p %p %p", cs, session, diam_ans, rad_fw, cli, stateful);
     83        TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli);
    8484        CHECK_PARAMS(cs);
    8585        TRACE_DEBUG(INFO, "RADIUS/Diameter Sample plugin received a new Diameter answer.");
  • extensions/app_radgw/rgwx_sip.c

    r974 r996  
    22* Software License Agreement (BSD License)                                                               *
    33* Author: Alexandre Westfahl <awestfahl@freediameter.net>                                                *
    4 *                                                                                                        *
     4*                                                                                                        *                                                                                               *
     5* Copyright (c) 2013, WIDE Project and NICT                                                              *
    56* Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project.    *             
    67*                                                                                                        *
     
    322323
    323324/* Handle an incoming RADIUS request */
    324 static int sip_rad_req( struct rgwp_config * cs, struct session ** session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
     325static int sip_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )
    325326{
    326327        int idx;
     
    340341        struct avp *auth_data=NULL, *auth=NULL, *avp = NULL;
    341342        union avp_value value;
    342        
    343         TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
    344        
    345         CHECK_PARAMS(rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw && session);
    346        
    347         //We check that session is not already filled
    348         if(*session)
    349         {
    350                 TRACE_DEBUG(INFO,"INTERNAL ERROR: We are not supposed to receive a session in radSIP plugin.");
    351                 return EINVAL;
    352         }
     343        struct session * sess;
     344       
     345        TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli);
     346       
     347        CHECK_PARAMS(rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw);
    353348       
    354349        /*
    355350           RFC5090 RADIUS Extension Digest Application
    356351        */
     352        CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_fw, &sess, NULL) );
     353        if (sess != NULL) {
     354                TRACE_DEBUG(INFO,"INTERNAL ERROR: We are not supposed to receive a session in radSIP plugin.");
     355                return EINVAL;         
     356        }
    357357       
    358358        /* Check basic information is there */
     
    398398                                        return EINVAL;
    399399                                }
    400                                 CHECK_FCT(fd_sess_fromsid (sid, sidlen, session, NULL));
     400                                CHECK_FCT(fd_sess_fromsid_msg (sid, sidlen, &sess, NULL));
    401401                                free(sid);
    402402                                                       
     
    424424
    425425        /* Create the session if it is not already done */
    426         if (!*session) {
     426        if (!sess) {
    427427               
    428428                DiamId_t fqdn;
     
    431431                size_t realm_len;
    432432               
    433                
    434                
    435                
    436433                /* Get information on the RADIUS client */
    437434                CHECK_FCT( rgw_clients_get_origin(cli, &fqdn, &fqdn_len, &realm, &realm_len) );
     
    440437                CHECK_MALLOC( sid = malloc(un_len + 1 /* ';' */ + fd_g_config->cnf_diamid_len + 1 /* '\0' */) );
    441438                sidlen = sprintf((char *)sid, "%.*s;%s", (int)un_len, un, fd_g_config->cnf_diamid);
    442                 CHECK_FCT( fd_sess_new(session, fqdn, fqdn_len, sid, sidlen) );
     439                CHECK_FCT( fd_sess_new(&sess, fqdn, fqdn_len, sid, sidlen) );
    443440                free(sid);
    444441        }
     442       
     443        /* Now, add the Session-Id AVP at beginning of Diameter message */
     444        CHECK_FCT( fd_msg_avp_new ( cs->dict.Session_Id, 0, &avp ) );
     445        value.os.data = sid;
     446        value.os.len = sidlen;
     447        CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
     448        CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
     449       
     450        TRACE_DEBUG(FULL, "[sip.rgwx] Translating new message for session '%s'...", sid);
     451       
     452        /* Now add this session in the message */
     453        CHECK_FCT( fd_msg_sess_set(*diam_fw, sess) );
    445454               
    446455        /* Add the Destination-Realm AVP */
     
    467476       
    468477        CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
    469         CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
    470        
    471         /* Now, add the Session-Id AVP at beginning of Diameter message */
    472         CHECK_FCT( fd_sess_getsid(*session, &sid, &sidlen) );
    473        
    474         TRACE_DEBUG(FULL, "[sip.rgwx] Translating new message for session '%s'...", sid);
    475        
    476         /* Add the Session-Id AVP as first AVP */
    477         CHECK_FCT( fd_msg_avp_new ( cs->dict.Session_Id, 0, &avp ) );
    478         value.os.data = sid;
    479         value.os.len = sidlen;
    480         CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
    481         CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
    482         CHECK_FCT( fd_msg_sess_set( *diam_fw, *session) );
     478        CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_LAST_CHILD, avp) );
    483479       
    484480        /*
     
    721717        //fd_msg_dump_walk(1,*diam_fw);
    722718       
    723         /* Store the request identifier in the session (if provided) */
    724         if (*session) {
     719        /* Store the request identifier in the session */
     720        {
    725721                unsigned char * req_sip;
    726722                CHECK_MALLOC(req_sip = malloc(16));
    727723                memcpy(req_sip, &rad_req->hdr->authenticator[0], 16);
    728724               
    729                 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &req_sip ) );
     725                CHECK_FCT( fd_sess_state_store( cs->sess_hdl, sess, &req_sip ) );
    730726        }
    731727       
     
    734730}
    735731
    736 static int sip_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * statefull )
     732static int sip_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli )
    737733{
    738734       
    739735       
    740         struct avp *avp, *next, *asid;
    741         struct avp_hdr *ahdr, *sid;
     736        struct avp *avp, *next;
     737        struct avp_hdr *ahdr;
    742738        //char buf[254]; /* to store some attributes values (with final '\0') */
    743739        unsigned char * req_sip = NULL;
    744        
    745         TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli);
    746         CHECK_PARAMS(cs && session && diam_ans && *diam_ans && rad_fw && *rad_fw);
    747        
    748        
    749        
     740        struct session * sess;
     741        os0_t sid = NULL;
     742        size_t sidlen;
     743       
     744        TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli);
     745        CHECK_PARAMS(cs && diam_ans && *diam_ans && rad_fw && *rad_fw);
    750746       
    751747       
     
    777773        }
    778774
    779 
    780775        /* Search the different AVPs we handle here */
    781         CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Session_Id, &asid) );
    782         CHECK_FCT( fd_msg_avp_hdr ( asid, &sid ) );
     776        CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_ans, &sess, NULL) );
     777        if (sess) {
     778                CHECK_FCT( fd_sess_getsid(sess, &sid, &sidlen) );
     779        }
     780
    783781
    784782        /* Check the Diameter error code */
     
    804802                        (*rad_fw)->hdr->code = RADIUS_CODE_ACCESS_REJECT;
    805803                        fd_log_debug("[sip.rgwx] Received Diameter answer with error code '%d', session %.*s, translating into Access-Reject",
    806                                         ahdr->avp_value->u32,
    807                                         sid->avp_value->os.len, sid->avp_value->os.data);
     804                                        ahdr->avp_value->u32, sidlen, sid);
    808805                        return 0;
    809806        }
     
    827824                                case DIAM_ATTR_DIGEST_NONCE:
    828825                                        CONV2RAD_STR(DIAM_ATTR_DIGEST_NONCE, ahdr->avp_value->os.data, ahdr->avp_value->os.len, 0);
    829                                         /* Retrieve the request identified which was stored in the session */
    830                                         if (session) {
    831                                                 os0_t sid=NULL;
    832                                                 size_t sidlen;
    833                                                 fd_sess_getsid (session, &sid, &sidlen );
    834                                                
    835                                                 nonce_add_element(ahdr->avp_value->os.data, ahdr->avp_value->os.len, sid, sidlen, cs);
    836                                         }
     826                                        nonce_add_element(ahdr->avp_value->os.data, ahdr->avp_value->os.len, sid, sidlen, cs);
    837827                                        break;
    838828                                case DIAM_ATTR_DIGEST_REALM:
     
    867857        }
    868858       
    869         if (session)
    870         {
    871                 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, session, &req_sip ) );
    872         }
     859        CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess, &req_sip ) );
    873860        free(req_sip);
    874        
    875861       
    876862        return 0;
Note: See TracChangeset for help on using the changeset viewer.