Navigation


Changeset 996:cf09fde3d7f5 in freeDiameter for extensions/app_radgw/rgwx_auth.c


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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) {
Note: See TracChangeset for help on using the changeset viewer.