Navigation


Changeset 356:e203fc0c95e3 in freeDiameter for extensions/app_radgw/rgwx_acct.c


Ignore:
Timestamp:
Jul 1, 2010, 3:47:34 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Updated the app_radgw extension to allow more souple management of sessions, and stateful gateway features.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_radgw/rgwx_acct.c

    r296 r356  
    285285
    286286/* Incoming RADIUS request */
    287 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 )
     287static 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 )
    288288{
    289289        int idx;
     
    300300        struct avp ** avp_tun = NULL, *avp = NULL;
    301301       
     302        const char * prefix = "Diameter/";
     303        size_t pref_len;
     304        char * si = NULL;
     305        size_t si_len = 0;
     306       
    302307        TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
    303308        CHECK_PARAMS(rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCOUNTING_REQUEST) && rad_ans && diam_fw && *diam_fw);
     309       
     310        pref_len = strlen(prefix);
    304311       
    305312        /*
     
    309316              port or the NAS does not distinguish among its ports.
    310317        */
     318        /* We also enforce that the message contains a CLASS attribute with Diameter/ prefix containing the Session-Id. */
    311319        for (idx = 0; idx < rad_req->attr_used; idx++) {
    312320                struct radius_attr_hdr * attr = (struct radius_attr_hdr *)(rad_req->buf + rad_req->attr_pos[idx]);
     
    342350                                                   |  v[3] ;
    343351                                break;
     352                               
     353                        case RADIUS_ATTR_CLASS:
     354                                {
     355                                        char * attr_val = (char *)(attr + 1);
     356                                        size_t attr_len = attr->length - sizeof(struct radius_attr_hdr);
     357                                        if ((attr_len > pref_len ) && ! strncmp(attr_val, prefix, pref_len)) {
     358                                                int i;
     359                                                si = attr_val + pref_len;
     360                                                si_len = attr_len - pref_len;
     361                                                TRACE_DEBUG(ANNOYING, "Found Class attribute with '%s' prefix (attr #%d), SI:'%.*s'.", prefix, idx, si_len, si);
     362                                                /* Remove from the message */
     363                                                for (i = idx + 1; i < rad_req->attr_used; i++)
     364                                                        rad_req->attr_pos[i - 1] = rad_req->attr_pos[i];
     365                                                rad_req->attr_used -= 1;
     366                                                break;
     367                                        }
     368                                }
     369                                break;
     370
    344371                }
    345372        }
     
    418445        }
    419446       
     447        /* Check if we got a valid session information, otherwise the server will not be able to handle the data... */
     448        if (!*session && !si) {
     449                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));
     450                return EINVAL;
     451        }
     452       
     453        /* Create the Session-Id AVP if needed */
     454        if (!*session) {
     455                CHECK_FCT( fd_sess_fromsid ( si, si_len, session, NULL) );
     456               
     457                TRACE_DEBUG(FULL, "[auth.rgwx] Translating new accounting message for session '%.*s'...", si_len, si);
     458               
     459                /* Add the Session-Id AVP as first AVP */
     460                CHECK_FCT( fd_msg_avp_new ( cs->dict.Session_Id, 0, &avp ) );
     461                value.os.data = (unsigned char *)si;
     462                value.os.len = si_len;
     463                CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) );
     464                CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) );
     465        }
     466               
    420467        /* Add the command code */
    421468        {
     
    10921139                }
    10931140                st->term_cause = str_cause;
    1094                 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, session, &st ) );
     1141                CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &st ) );
    10951142        }
    10961143       
     
    11281175}
    11291176
    1130 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 )
     1177static 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 )
    11311178{
    11321179        struct sess_state * st = NULL;
Note: See TracChangeset for help on using the changeset viewer.