Changeset 996:cf09fde3d7f5 in freeDiameter for extensions/app_radgw/rgwx_sip.c
- Timestamp:
- Mar 20, 2013, 12:13:14 AM (11 years ago)
- Branch:
- default
- Children:
- 997:632913581c37, 998:ad6c1ee04d2d
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/app_radgw/rgwx_sip.c
r974 r996 2 2 * Software License Agreement (BSD License) * 3 3 * Author: Alexandre Westfahl <awestfahl@freediameter.net> * 4 * * 4 * * * 5 * Copyright (c) 2013, WIDE Project and NICT * 5 6 * Copyright (c) 2010, Alexandre Westfahl, Teraoka Laboratory (Keio University), and the WIDE Project. * 6 7 * * … … 322 323 323 324 /* Handle an incoming RADIUS request */ 324 static int sip_rad_req( struct rgwp_config * cs, struct session ** session, structradius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )325 static 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 ) 325 326 { 326 327 int idx; … … 340 341 struct avp *auth_data=NULL, *auth=NULL, *avp = NULL; 341 342 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); 353 348 354 349 /* 355 350 RFC5090 RADIUS Extension Digest Application 356 351 */ 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 } 357 357 358 358 /* Check basic information is there */ … … 398 398 return EINVAL; 399 399 } 400 CHECK_FCT(fd_sess_fromsid (sid, sidlen, session, NULL));400 CHECK_FCT(fd_sess_fromsid_msg (sid, sidlen, &sess, NULL)); 401 401 free(sid); 402 402 … … 424 424 425 425 /* Create the session if it is not already done */ 426 if (! *session) {426 if (!sess) { 427 427 428 428 DiamId_t fqdn; … … 431 431 size_t realm_len; 432 432 433 434 435 436 433 /* Get information on the RADIUS client */ 437 434 CHECK_FCT( rgw_clients_get_origin(cli, &fqdn, &fqdn_len, &realm, &realm_len) ); … … 440 437 CHECK_MALLOC( sid = malloc(un_len + 1 /* ';' */ + fd_g_config->cnf_diamid_len + 1 /* '\0' */) ); 441 438 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) ); 443 440 free(sid); 444 441 } 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) ); 445 454 446 455 /* Add the Destination-Realm AVP */ … … 467 476 468 477 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) ); 483 479 484 480 /* … … 721 717 //fd_msg_dump_walk(1,*diam_fw); 722 718 723 /* Store the request identifier in the session (if provided)*/724 if (*session){719 /* Store the request identifier in the session */ 720 { 725 721 unsigned char * req_sip; 726 722 CHECK_MALLOC(req_sip = malloc(16)); 727 723 memcpy(req_sip, &rad_req->hdr->authenticator[0], 16); 728 724 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 ) ); 730 726 } 731 727 … … 734 730 } 735 731 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)732 static int sip_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) 737 733 { 738 734 739 735 740 struct avp *avp, *next , *asid;741 struct avp_hdr *ahdr , *sid;736 struct avp *avp, *next; 737 struct avp_hdr *ahdr; 742 738 //char buf[254]; /* to store some attributes values (with final '\0') */ 743 739 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); 750 746 751 747 … … 777 773 } 778 774 779 780 775 /* 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 783 781 784 782 /* Check the Diameter error code */ … … 804 802 (*rad_fw)->hdr->code = RADIUS_CODE_ACCESS_REJECT; 805 803 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); 808 805 return 0; 809 806 } … … 827 824 case DIAM_ATTR_DIGEST_NONCE: 828 825 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); 837 827 break; 838 828 case DIAM_ATTR_DIGEST_REALM: … … 867 857 } 868 858 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 ) ); 873 860 free(req_sip); 874 875 861 876 862 return 0;
Note: See TracChangeset
for help on using the changeset viewer.