Navigation


Changeset 996:cf09fde3d7f5 in freeDiameter for extensions/app_radgw/rgwx_sip.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_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.