From: Vincent Cheng <vincent.cheng...@renesas.com>

Signed-off-by: Vincent Cheng <vincent.cheng...@renesas.com>
---
 port.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/port.c b/port.c
index f2b666c..0169161 100644
--- a/port.c
+++ b/port.c
@@ -167,6 +167,27 @@ static int msg_source_equal(struct ptp_message *m1, struct 
foreign_clock *fc)
        return 0 == memcmp(id1, id2, sizeof(*id1));
 }
 
+static int port_unicast_message_valid(struct port *p, struct ptp_message *m)
+{
+       struct unicast_master_address master;
+
+       if (!unicast_client_unicast_master_table_received(p, m)) {
+               memset(&master, 0, sizeof(master));
+               master.address = m->address;
+               master.portIdentity = m->header.sourcePortIdentity;
+
+               pr_warning("%s: new foreign master %s not in unicast master 
table",
+                          p->log_name, pid2str(&m->header.sourcePortIdentity));
+
+               if (unicast_client_tx_cancel(p, &master)) {
+                       pr_warning("%s: cancel unicast transmission to %s 
failed",
+                                  p->log_name, 
pid2str(&m->header.sourcePortIdentity));
+               }
+               return 0;
+       }
+       return 1;
+}
+
 int source_pid_eq(struct ptp_message *m1, struct ptp_message *m2)
 {
        return pid_eq(&m1->header.sourcePortIdentity,
@@ -351,8 +372,13 @@ static int add_foreign_master(struct port *p, struct 
ptp_message *m)
                }
        }
        if (!fc) {
+               if (unicast_client_enabled(p)) {
+                       if (!port_unicast_message_valid(p, m)) {
+                               return 0;
+                       }
+               }
                pr_notice("%s: new foreign master %s", p->log_name,
-                       pid2str(&m->header.sourcePortIdentity));
+                         pid2str(&m->header.sourcePortIdentity));
 
                fc = malloc(sizeof(*fc));
                if (!fc) {
-- 
2.34.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to