Blob Blame History Raw
commit c304dbe4060da421a9bf089188c5016ef97aacf1
Author: Vadim Fedorenko <vadfed@meta.com>
Date:   Fri Jan 13 12:34:34 2023 -0800

    unicast_client: further improve CANCEL logic
    
    bc_dispatch should work right after recieving CANCEL otherwise
    state machine can stuck in HAVE_ANN state.
    
    Also another code to be safe on this side and recover selected
    best master from being stuck in HAVE_ANN state.
    
    Signed-off-by: Vadim Fedorenko <vadfed@meta.com>

diff --git a/port.c b/port.c
index 6b5483f..02b49a1 100644
--- a/port.c
+++ b/port.c
@@ -2982,8 +2982,11 @@ static enum fsm_event bc_event(struct port *p, int fd_index)
 			event = EV_STATE_DECISION_EVENT;
 		break;
 	case SIGNALING:
-		if (process_signaling(p, msg)) {
+		err = process_signaling(p, msg);
+		if (err < 0) {
 			event = EV_FAULT_DETECTED;
+		} else if (err) {
+			event = EV_STATE_DECISION_EVENT;
 		}
 		break;
 	case MANAGEMENT:
diff --git a/unicast_client.c b/unicast_client.c
index 81113ae..633a4fe 100644
--- a/unicast_client.c
+++ b/unicast_client.c
@@ -363,7 +363,7 @@ int unicast_client_cancel(struct port *p, struct ptp_message *m,
 	}
 out:
 	msg_put(msg);
-	return err;
+	return err ? err : 1;
 }
 
 int unicast_client_initialize(struct port *p)
@@ -433,6 +433,7 @@ int unicast_client_enabled(struct port *p)
 void unicast_client_grant(struct port *p, struct ptp_message *m,
 			  struct tlv_extra *extra)
 {
+	struct PortIdentity pid = clock_parent_identity(p->clock);
 	struct unicast_master_address *ucma;
 	struct grant_unicast_xmit_tlv *g;
 	int mtype;
@@ -478,6 +479,15 @@ void unicast_client_grant(struct port *p, struct ptp_message *m,
 
 	switch (ucma->state) {
 	case UC_HAVE_ANN:
+		if (mtype == ANNOUNCE) {
+			if (pid_eq(&ucma->portIdentity, &pid)) {
+				ucma->state = UC_NEED_SYDY;
+				pr_warning("received ANNOUNCE grant for current master in UC_HAVE_ANN state, unblocking");
+			}
+			ucma->portIdentity = m->header.sourcePortIdentity;
+			unicast_client_set_renewal(p, ucma, g->durationField);
+		}
+		break;
 	case UC_WAIT:
 		if (mtype == ANNOUNCE) {
 			ucma->state = unicast_fsm(ucma->state, UC_EV_GRANT_ANN);