Пример #1
0
void Send_ASR(cdp_session_t* s, AAAMessage* msg) {
    AAAMessage *asr = 0;
    AAA_AVP *avp = 0;
    peer *p = 0;
    char x[4];
    LM_DBG("Send_ASR() : sending ASR\n");
    asr = AAACreateRequest(s->application_id, IMS_ASR, Flag_Proxyable, s);

    if (!asr) {
        LM_ERR("Send_ASR(): error creating ASR!\n");
        return;
    }

    set_4bytes(x, s->application_id);
    avp = AAACreateAVP(AVP_Auth_Application_Id, AAA_AVP_FLAG_MANDATORY, 0, x, 4, AVP_DUPLICATE_DATA);
    AAAAddAVPToMessage(asr, avp, asr->avpList.tail);

    set_4bytes(x, 3); // Not specified
    avp = AAACreateAVP(AVP_IMS_Abort_Cause, AAA_AVP_FLAG_MANDATORY, 0, x, 4, AVP_DUPLICATE_DATA);
    AAAAddAVPToMessage(asr, avp, asr->avpList.tail);
    //todo - add all the other avps

    p = get_routing_peer(s, asr);
    if (!p) {
        LM_ERR("unable to get routing peer in Send_ASR \n");
        if (asr) AAAFreeMessage(&asr); //needed in frequency
    }

    if (!peer_send_msg(p, asr)) {
        if (asr) AAAFreeMessage(&asr); //needed in frequency
    } else
        LM_DBG("success sending ASR\n");
}
Пример #2
0
/**
 * Send a AAAMessage asynchronously.
 * When the response is received, the callback_f(callback_param,...) is called.
 * @param message - the request to be sent
 * @param peer_id - FQDN of the peer to send
 * @param callback_f - callback to be called on transactional response or transaction timeout
 * @param callback_param - generic parameter to call the transactional callback function with
 * @returns 1 on success, 0 on failure 
 * \todo remove peer_id and add Realm routing
 */
AAAReturnCode AAASendMessage(	
		AAAMessage *message,
		AAATransactionCallback_f *callback_f,
		void *callback_param)
{
	peer *p;
	p = get_routing_peer(message);
	if (!p) {
		LOG(L_ERR,"ERROR:AAASendMessage(): Can't find a suitable connected peer in the routing table.\n");
		goto error;
	}
	if (p->state!=I_Open && p->state!=R_Open){
		LOG(L_ERR,"ERROR:AAASendMessage(): Peer not connected to %.*s\n",p->fqdn.len,p->fqdn.s);
		goto error;
	}
	/* only add transaction following when required */
	if (callback_f){
		if (is_req(message))
			cdp_add_trans(message,callback_f,callback_param,config->transaction_timeout,1);
		else
			LOG(L_ERR,"ERROR:AAASendMessage(): can't add transaction callback for answer.\n");
	}
	
//	if (!peer_send_msg(p,message))
	if (!sm_process(p,Send_Message,message,0,0))	
		goto error;
		
	return 1;
error:	
	AAAFreeMessage(&message);
	return 0;
}
Пример #3
0
void Send_STR(cdp_session_t* s, AAAMessage* msg)
{
	AAAMessage *str=0;
	AAA_AVP *avp=0;
	peer *p=0;
	char x[4];
	LOG(L_DBG, "sending STR\n");
	//if (msg) LOG(L_DBG,"Send_STR() : sending STR for %d, flags %#1x endtoend %u hopbyhop %u\n",msg->commandCode,msg->flags,msg->endtoendId,msg->hopbyhopId);
	//else LOG(L_DBG,"Send_STR() called from AAATerminateAuthSession or some other event\n");
	str = AAACreateRequest(s->application_id,IMS_STR,Flag_Proxyable,s);
	
	if (!str) {
		LOG(L_ERR,"ERR:Send_STR(): error creating STR!\n");
		return;
	}
	if(!dup_routing_avps(msg, str)){
		LOG(L_ERR,"ERR:Send_STR(): error duplicating routing AVPs!\n");
		AAAFreeMessage(&str);
		return;
	}
	if(s->vendor_id!=0 && !add_vendor_specific_application_id_group(str,s->vendor_id,s->application_id)){ 
		LOG(L_ERR,"ERR:Send_STR(): error adding Vendor-Id-Specific-Application-Id Group!\n");
		AAAFreeMessage(&str);
		return;
	}
	
	set_4bytes(x,s->application_id);
	avp = AAACreateAVP(AVP_Auth_Application_Id,AAA_AVP_FLAG_MANDATORY,0,x,4,AVP_DUPLICATE_DATA);
	AAAAddAVPToMessage(str,avp,str->avpList.tail);
	
	set_4bytes(x,4); // Diameter_administrative
	avp = AAACreateAVP(AVP_Termination_Cause,AAA_AVP_FLAG_MANDATORY,0,x,4,AVP_DUPLICATE_DATA);
	AAAAddAVPToMessage(str,avp,str->avpList.tail);
	//todo - add all the other avps

	p = get_routing_peer(str);
	if (!p) {
		LOG(L_ERR,"unable to get routing peer in Send_STR \n");
		if (str) AAAFreeMessage(&str); //needed in frequency
		return;
	}
	//if (str) LOG(L_CRIT,"Send_STR() : sending STR  %d, flags %#1x endtoend %u hopbyhop %u\n",str->commandCode,str->flags,str->endtoendId,str->hopbyhopId);
	if (!peer_send_msg(p,str))
	{
		LOG(L_DBG,"Send_STR peer_send_msg return error!\n");
		if (str) AAAFreeMessage(&str); //needed in frequency	
	} else { 
		LOG(L_DBG,"success sending STR\n");
	}
}
Пример #4
0
/**
 * Send a AAAMessage synchronously.
 * This blocks until a response is received or a transactional time-out happens. 
 * @param message - the request to be sent
 * @param peer_id - FQDN of the peer to send
 * @returns 1 on success, 0 on failure 
 * \todo remove peer_id and add Realm routing
 * \todo replace the busy-waiting lock in here with one that does not consume CPU
 */
AAAMessage* AAASendRecvMessage(AAAMessage *message)
{
	peer *p;
	gen_sem_t *sem=0;
	cdp_trans_t *t;
	AAAMessage *ans;
	
	p = get_routing_peer(message);
	if (!p) {
		LOG(L_ERR,"ERROR:AAASendRecvMessage(): Can't find a suitable connected peer in the routing table.\n");
		goto error;
	}
	if (p->state!=I_Open && p->state!=R_Open){
		LOG(L_ERR,"ERROR:AAASendRecvMessage(): Peer not connected to %.*s\n",p->fqdn.len,p->fqdn.s);
		goto error;
	}
	
	
	if (is_req(message)){
		sem_new(sem,0);
		t = cdp_add_trans(message,sendrecv_cb,(void*)sem,config->transaction_timeout,0);

//		if (!peer_send_msg(p,message)) {
		if (!sm_process(p,Send_Message,message,0,0)){	
			sem_free(sem);	
			goto error;
		}

		/* block until callback is executed */
		while(sem_get(sem)<0){
			if (shutdownx&&(*shutdownx)) goto error;
			LOG(L_WARN,"WARN:AAASendRecvMessage(): interrupted by signal or something > %s\n",strerror(errno));
		}
		sem_free(sem);		
		ans = t->ans;
		cdp_free_trans(t);
		return ans;
	} else {
		LOG(L_ERR,"ERROR:AAASendRecvMessage(): can't add wait for answer to answer.\n");
		goto error;
	}

		
error:	
out_of_memory:
	AAAFreeMessage(&message);
	return 0;
}
Пример #5
0
void Send_STR(cdp_session_t* s, AAAMessage* msg) {
    AAAMessage *str = 0;
    AAA_AVP *avp = 0;
    peer *p = 0;
    char x[4];
    LM_DBG("sending STR\n");
    //if (msg) LM_DBG("Send_STR() : sending STR for %d, flags %#1x endtoend %u hopbyhop %u\n",msg->commandCode,msg->flags,msg->endtoendId,msg->hopbyhopId);
    //else LM_DBG("Send_STR() called from AAATerminateAuthSession or some other event\n");
    str = AAACreateRequest(s->application_id, IMS_STR, Flag_Proxyable, s);

    if (!str) {
        LM_ERR("Send_STR(): error creating STR!\n");
        return;
    }
    if (!dup_routing_avps(msg, str)) {
        LM_ERR("Send_STR(): error duplicating routing AVPs!\n");
        AAAFreeMessage(&str);
        return;
    }
    if (s->vendor_id != 0 && !add_vendor_specific_application_id_group(str, s->vendor_id, s->application_id)) {
        LM_ERR("Send_STR(): error adding Vendor-Id-Specific-Application-Id Group!\n");
        AAAFreeMessage(&str);
        return;
    }

    //Richard added this - if timers expire dest realm is not here!
    LM_DBG("Adding dest realm if not there already...\n");
    LM_DBG("Destination realm: [%.*s] \n", s->dest_realm.len, s->dest_realm.s);
    /* Add Destination-Realm AVP, if not already there */
    avp = AAAFindMatchingAVP(str, str->avpList.head, AVP_Destination_Realm, 0, AAA_FORWARD_SEARCH);
    if (!avp) {
        avp = AAACreateAVP(AVP_Destination_Realm, AAA_AVP_FLAG_MANDATORY, 0,
                s->dest_realm.s, s->dest_realm.len, AVP_DUPLICATE_DATA);
        AAAAddAVPToMessage(str, avp, str->avpList.tail);
    }




    set_4bytes(x, s->application_id);
    avp = AAACreateAVP(AVP_Auth_Application_Id, AAA_AVP_FLAG_MANDATORY, 0, x, 4, AVP_DUPLICATE_DATA);
    AAAAddAVPToMessage(str, avp, str->avpList.tail);

    set_4bytes(x, 4); // Diameter_administrative
    avp = AAACreateAVP(AVP_Termination_Cause, AAA_AVP_FLAG_MANDATORY, 0, x, 4, AVP_DUPLICATE_DATA);
    AAAAddAVPToMessage(str, avp, str->avpList.tail);
    //todo - add all the other avps

    /* we are already locked on the auth session*/
    p = get_routing_peer(s, str);

    if (!p) {
        LM_ERR("unable to get routing peer in Send_STR \n");
        if (str) AAAFreeMessage(&str); //needed in frequency
        return;
    }
    //if (str) LM_CRIT("Send_STR() : sending STR  %d, flags %#1x endtoend %u hopbyhop %u\n",str->commandCode,str->flags,str->endtoendId,str->hopbyhopId);
    if (!peer_send_msg(p, str)) {
        LM_DBG("Send_STR peer_send_msg return error!\n");
        if (str) AAAFreeMessage(&str); //needed in frequency
    } else {
        LM_DBG("success sending STR\n");
    }
}