Navigation


Changeset 996:cf09fde3d7f5 in freeDiameter for extensions/app_radgw/rgwx_acct.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_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 */
Note: See TracChangeset for help on using the changeset viewer.