comparison libfdcore/peers.c @ 749:2557127f3c8b

fix bug reported by Vjacheslav Chekushin on the mailing-list (thanks\!)
author Sebastien Decugis <sdecugis@nict.go.jp>
date Sun, 07 Aug 2011 21:03:49 +0200
parents 5d529eb0ad33
children c47c16436f71
comparison
equal deleted inserted replaced
748:1f721af3cac3 749:2557127f3c8b
453 TRACE_ENTRY("%p %p", cer, cnx); 453 TRACE_ENTRY("%p %p", cer, cnx);
454 CHECK_PARAMS(cer && *cer && cnx && *cnx); 454 CHECK_PARAMS(cer && *cer && cnx && *cnx);
455 455
456 msg = *cer; 456 msg = *cer;
457 457
458 /* If needed, resolve the dictioanry model for Origin-Host */ 458 /* If needed, resolve the dictionary model for Origin-Host */
459 CHECK_POSIX( pthread_mutex_lock(&cache_avp_lock) ); 459 CHECK_POSIX( pthread_mutex_lock(&cache_avp_lock) );
460 if (!avp_oh_model) { 460 if (!avp_oh_model) {
461 avp_code_t code = AC_ORIGIN_HOST; 461 avp_code_t code = AC_ORIGIN_HOST;
462 int ret; 462 int ret;
463 CHECK_FCT_DO( ret = fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE, &code, &avp_oh_model, ENOENT), 463 CHECK_FCT_DO( ret = fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_CODE, &code, &avp_oh_model, ENOENT),
468 /* Find the Diameter Identity of the remote peer in the message */ 468 /* Find the Diameter Identity of the remote peer in the message */
469 CHECK_FCT( fd_msg_search_avp ( msg, avp_oh_model, &avp_oh ) ); 469 CHECK_FCT( fd_msg_search_avp ( msg, avp_oh_model, &avp_oh ) );
470 ASSERT(avp_oh); /* otherwise it should not have passed rules validation, right? */ 470 ASSERT(avp_oh); /* otherwise it should not have passed rules validation, right? */
471 CHECK_FCT( fd_msg_avp_hdr ( avp_oh, &avp_hdr ) ); 471 CHECK_FCT( fd_msg_avp_hdr ( avp_oh, &avp_hdr ) );
472 472
473 /* First, check if the Origin-Host value */ 473 /* First, check if the Origin-Host value is valid */
474 if (!fd_os_is_valid_DiameterIdentity(avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len)) { 474 if (!fd_os_is_valid_DiameterIdentity(avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len)) {
475 TRACE_DEBUG(INFO, "Received new CER with invalid Origin-Host"); 475 TRACE_DEBUG(INFO, "Received new CER with invalid Origin-Host");
476 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, cer, MSGFL_ANSW_ERROR ) ); 476 CHECK_FCT( fd_msg_new_answer_from_req ( fd_g_config->cnf_dict, cer, MSGFL_ANSW_ERROR ) );
477 CHECK_FCT( fd_msg_rescode_set(*cer, "ER_DIAMETER_INVALID_AVP_VALUE", 477 CHECK_FCT( fd_msg_rescode_set(*cer, "ER_DIAMETER_INVALID_AVP_VALUE",
478 "Your Origin-Host contains invalid characters.", avp_oh, 1 ) ); 478 "Your Origin-Host contains invalid characters.", avp_oh, 1 ) );
486 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_peers_rw) ); 486 CHECK_POSIX( pthread_rwlock_wrlock(&fd_g_peers_rw) );
487 487
488 li_inf = &fd_g_peers; 488 li_inf = &fd_g_peers;
489 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) { 489 for (li = fd_g_peers.next; li != &fd_g_peers; li = li->next) {
490 int cmp, cont; 490 int cmp, cont;
491 peer = (struct fd_peer *)li->o; 491 peer = (struct fd_peer *)li;
492 cmp = fd_os_almostcasesrch( avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen, &cont ); 492 cmp = fd_os_almostcasesrch( avp_hdr->avp_value->os.data, avp_hdr->avp_value->os.len, peer->p_hdr.info.pi_diamid, peer->p_hdr.info.pi_diamidlen, &cont );
493 if (cmp < 0) { 493 if (cmp > 0) {
494 li_inf = li; 494 li_inf = li;
495 continue;
496 } 495 }
497 if (cmp == 0) { 496 if (cmp == 0) {
498 found = 1; 497 found = 1;
499 break; 498 break;
500 } 499 }
517 516
518 /* Set this peer to expire on inactivity */ 517 /* Set this peer to expire on inactivity */
519 peer->p_hdr.info.config.pic_flags.exp = PI_EXP_INACTIVE; 518 peer->p_hdr.info.config.pic_flags.exp = PI_EXP_INACTIVE;
520 peer->p_hdr.info.config.pic_lft = 3600; /* 1 hour without any message 519 peer->p_hdr.info.config.pic_lft = 3600; /* 1 hour without any message
521 -- RFC3539 states that this must not be inferior to BRINGDOWN_INTERVAL = 5 minutes */ 520 -- RFC3539 states that this must not be inferior to BRINGDOWN_INTERVAL = 5 minutes */
521 CHECK_FCT_DO( ret = fd_p_expi_update( peer ), goto out );
522
522 523
523 /* Insert the new peer in the list (the PSM will take care of setting the expiry after validation) */ 524 /* Insert the new peer in the list (the PSM will take care of setting the expiry after validation) */
524 fd_list_insert_after( li_inf, &peer->p_hdr.chain ); 525 fd_list_insert_after( li_inf, &peer->p_hdr.chain );
525 526
526 /* Start the PSM, which will receive the event bellow */ 527 /* Start the PSM, which will receive the event bellow */
"Welcome to our mercurial repository"