Mercurial > hg > freeDiameter
comparison freeDiameter/p_psm.c @ 154:4356de61174d
Small tweaks in the PSM
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 22 Dec 2009 15:53:13 +0900 |
parents | abd3c441780b |
children | 94898702db87 |
comparison
equal
deleted
inserted
replaced
153:06843b78534e | 154:4356de61174d |
---|---|
382 /* Parse the received buffer */ | 382 /* Parse the received buffer */ |
383 CHECK_FCT_DO( fd_msg_parse_buffer( (void *)&ev_data, ev_sz, &msg), | 383 CHECK_FCT_DO( fd_msg_parse_buffer( (void *)&ev_data, ev_sz, &msg), |
384 { | 384 { |
385 fd_log_debug("Received invalid data from peer '%s', closing the connection\n", peer->p_hdr.info.pi_diamid); | 385 fd_log_debug("Received invalid data from peer '%s', closing the connection\n", peer->p_hdr.info.pi_diamid); |
386 free(ev_data); | 386 free(ev_data); |
387 goto psm_reset; | 387 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL), goto psm_reset ); |
388 goto psm_loop; | |
388 } ); | 389 } ); |
389 | 390 |
390 TRACE_DEBUG(FULL, "Received a message (%zdb) from '%s'", ev_sz, peer->p_hdr.info.pi_diamid); | 391 TRACE_DEBUG(FULL, "Received a message (%zdb) from '%s'", ev_sz, peer->p_hdr.info.pi_diamid); |
391 fd_msg_dump_one(FULL, msg); | 392 fd_msg_dump_one(FULL, msg); |
392 | 393 |
460 if (msg) { | 461 if (msg) { |
461 CHECK_FCT_DO( fd_msg_free(msg), goto psm_end); | 462 CHECK_FCT_DO( fd_msg_free(msg), goto psm_end); |
462 } | 463 } |
463 } else { | 464 } else { |
464 /* We received an invalid answer, let's disconnect */ | 465 /* We received an invalid answer, let's disconnect */ |
465 goto psm_reset; | 466 CHECK_FCT_DO( fd_event_send(peer->p_events, FDEVP_CNX_ERROR, 0, NULL), goto psm_reset ); |
466 } | 467 } |
467 goto psm_loop; | 468 goto psm_loop; |
468 } | 469 } |
469 } | 470 } |
470 | 471 |
471 /* Handle the LL message and update the expiry timer appropriately */ | 472 /* Handle the LL message and update the expiry timer appropriately */ |
472 switch (hdr->msg_code) { | 473 switch (hdr->msg_code) { |
473 case CC_CAPABILITIES_EXCHANGE: | 474 case CC_CAPABILITIES_EXCHANGE: |
474 CHECK_FCT_DO( fd_p_ce_msgrcv(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_end ); | 475 CHECK_FCT_DO( fd_p_ce_msgrcv(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_reset ); |
475 break; | 476 break; |
476 | 477 |
477 case CC_DISCONNECT_PEER: | 478 case CC_DISCONNECT_PEER: |
478 CHECK_FCT_DO( fd_p_dp_handle(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_end ); | 479 CHECK_FCT_DO( fd_p_dp_handle(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_reset ); |
479 if (peer->p_hdr.info.runtime.pir_state == STATE_CLOSING) | 480 if (peer->p_hdr.info.runtime.pir_state == STATE_CLOSING) |
480 goto psm_end; | 481 goto psm_end; |
481 break; | 482 break; |
482 | 483 |
483 case CC_DEVICE_WATCHDOG: | 484 case CC_DEVICE_WATCHDOG: |
484 CHECK_FCT_DO( fd_p_dw_handle(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_end ); | 485 CHECK_FCT_DO( fd_p_dw_handle(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_reset ); |
485 break; | 486 break; |
486 | 487 |
487 default: | 488 default: |
488 /* Unknown / unexpected / invalid message */ | 489 /* Unknown / unexpected / invalid message */ |
489 fd_log_debug("Received an unknown local message from peer '%s', discarded.\n", peer->p_hdr.info.pi_diamid); | 490 fd_log_debug("Received an unknown local message from peer '%s', discarded.\n", peer->p_hdr.info.pi_diamid); |
537 case STATE_WAITCNXACK: | 538 case STATE_WAITCNXACK: |
538 case STATE_SUSPECT: | 539 case STATE_SUSPECT: |
539 default: | 540 default: |
540 /* Mark the connection problem */ | 541 /* Mark the connection problem */ |
541 peer->p_flags.pf_cnx_pb = 1; | 542 peer->p_flags.pf_cnx_pb = 1; |
543 | |
544 /* Destroy the connection, restart the timer to a new connection attempt */ | |
545 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc); | |
542 goto psm_reset; | 546 goto psm_reset; |
543 | 547 |
544 case STATE_CLOSED: | 548 case STATE_CLOSED: |
545 /* Just ignore */ | 549 /* Just ignore */ |
546 break; | 550 break; |
637 CHECK_FCT_DO( fd_p_ce_process_receiver(peer), goto psm_end ); | 641 CHECK_FCT_DO( fd_p_ce_process_receiver(peer), goto psm_end ); |
638 break; | 642 break; |
639 | 643 |
640 case STATE_WAITCNXACK: | 644 case STATE_WAITCNXACK: |
641 /* Go back to CLOSE */ | 645 /* Go back to CLOSE */ |
642 fd_psm_cleanup(peer, 0); | |
643 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc); | 646 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc); |
644 break; | 647 goto psm_reset; |
645 | 648 |
646 default: | 649 default: |
647 /* Just ignore */ | 650 /* Just ignore */ |
648 TRACE_DEBUG(FULL, "Connection attempt failed but current state is %s, ignoring...", STATE_STR(peer->p_hdr.info.runtime.pir_state)); | 651 TRACE_DEBUG(FULL, "Connection attempt failed but current state is %s, ignoring...", STATE_STR(peer->p_hdr.info.runtime.pir_state)); |
649 } | 652 } |
668 case STATE_CLOSING: | 671 case STATE_CLOSING: |
669 case STATE_SUSPECT: | 672 case STATE_SUSPECT: |
670 case STATE_WAITCNXACK: | 673 case STATE_WAITCNXACK: |
671 case STATE_WAITCEA: | 674 case STATE_WAITCEA: |
672 /* Destroy the connection, restart the timer to a new connection attempt */ | 675 /* Destroy the connection, restart the timer to a new connection attempt */ |
673 fd_psm_cleanup(peer, 0); | |
674 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc); | 676 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc); |
675 goto psm_loop; | 677 goto psm_reset; |
676 | 678 |
677 case STATE_WAITCNXACK_ELEC: | 679 case STATE_WAITCNXACK_ELEC: |
678 /* Abort the initiating side */ | 680 /* Abort the initiating side */ |
679 fd_p_cnx_abort(peer, 0); | 681 fd_p_cnx_abort(peer, 0); |
680 /* Process the receiver side */ | 682 /* Process the receiver side */ |
684 } | 686 } |
685 | 687 |
686 /* Default action : the handling has not yet been implemented. [for debug only] */ | 688 /* Default action : the handling has not yet been implemented. [for debug only] */ |
687 TRACE_DEBUG(INFO, "Missing handler in PSM for '%s'\t<-- '%s'", STATE_STR(peer->p_hdr.info.runtime.pir_state), fd_pev_str(event)); | 689 TRACE_DEBUG(INFO, "Missing handler in PSM for '%s'\t<-- '%s'", STATE_STR(peer->p_hdr.info.runtime.pir_state), fd_pev_str(event)); |
688 psm_reset: | 690 psm_reset: |
691 if (peer->p_flags.pf_delete) | |
692 goto psm_end; | |
689 fd_psm_cleanup(peer, 0); | 693 fd_psm_cleanup(peer, 0); |
690 fd_psm_next_timeout(peer, 0, 0); | |
691 goto psm_loop; | 694 goto psm_loop; |
692 | 695 |
693 psm_end: | 696 psm_end: |
694 fd_psm_cleanup(peer, 1); | 697 fd_psm_cleanup(peer, 1); |
695 pthread_cleanup_pop(1); /* set STATE_ZOMBIE */ | 698 pthread_cleanup_pop(1); /* set STATE_ZOMBIE */ |