Eric Decker
-----Original Message-----
From: Eric Decker <decker0...@gmail.com>
Sent: Friday, July 2, 2021 11:40 PM
To: linuxptp-devel@lists.sourceforge.net
Cc: Eric Decker <edec...@oldi.com>
Subject: [PATCH] Always send with a unique sequence count from uds. Only
forward responses to UDS port with corresponding requests on the UDS port.
Signed-off-by: Eric Decker <edec...@oldi.com>
---
clock.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 70 insertions(+), 3 deletions(-)
diff --git a/clock.c b/clock.c
index d428ae2..3006bf9 100644
--- a/clock.c
+++ b/clock.c
@@ -1381,7 +1381,8 @@ static int clock_do_forward_mgmt(struct clock *c,
return 0;
/* Don't forward any requests to the UDS-RW port
- (the UDS-RO port doesn't allow any forwarding). */
+ (the UDS-RO port doesn't allow any forwarding).
+ Do forward responses. */
if (out == c->uds_rw_port) {
switch (management_action(msg)) {
case GET:
@@ -1404,17 +1405,83 @@ static void clock_forward_mgmt_msg(struct clock *c,
struct port *p, struct ptp_m {
struct port *piter;
int pdulen = 0, msg_ready = 0;
+ static UInteger16 mgmt_seq_count = 0;
+ UInteger16 temp_seq_count = 0;
+ struct uds_mgmt_req {
+ UInteger16 seqId;
+ Enumeration16 id;
+ };
+ #define MGMT_REQ_Q_SIZE 4
+ static struct uds_mgmt_req uds_req[MGMT_REQ_Q_SIZE] = {0};
+ static unsigned int uds_req_index = 0;
+ int forward_to_uds = 0;
+ struct management_tlv *mgt = (struct management_tlv *)
+msg->management.suffix;
+
if (forwarding(c, p) && msg->management.boundaryHops) {
pdulen = msg->header.messageLength;
msg->management.boundaryHops--;
+
+ if (p == c->uds_rw_port)
+ {
+ /* Always send with a unique sequence count and correct
clock identity.
+ If ingress port is uds port (pmc) then increment
sequence count. */
+ temp_seq_count = msg->header.sequenceId;
+ msg->header.sequenceId = mgmt_seq_count++;
+ msg->header.sourcePortIdentity.clockIdentity =
clock_identity(c);
+
+ /* Record outgoing requests from uds port.
+ We will only forward responses to those requests to
uds port. */
+ switch (management_action(msg)) {
+ case GET:
+ case SET:
+ case COMMAND:
+ if ( strstr(msg->address.sun.sun_path, "pmc")
!= NULL ||
+ strstr(msg->address.sun.sun_path,
"phc2sys")) {
+ uds_req[uds_req_index].id = mgt->id;
+ uds_req[uds_req_index].seqId =
msg->header.sequenceId;
+ uds_req_index++;
+ if ( uds_req_index >= MGMT_REQ_Q_SIZE )
uds_req_index = 0;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ /* Only forward responses to UDS port with corresponding
requests on the UDS port. */
+ switch (management_action(msg)) {
+ case GET:
+ case SET:
+ case COMMAND:
+ break;
+ default:
+ for ( unsigned int x = 0; x < MGMT_REQ_Q_SIZE; x++)
+ {
+ /* We don't have a destination addresss yet. */
+ if( uds_req[x].id == mgt->id &&
+ uds_req[x].seqId ==
msg->header.sequenceId ) {
+ forward_to_uds = 1;
+ break;
+ }
+ }
+ break;
+ }
+
LIST_FOREACH(piter, &c->ports, list) {
if (clock_do_forward_mgmt(c, p, piter, msg, &msg_ready))
pr_err("%s: management forward failed",
port_log_name(piter));
}
- if (clock_do_forward_mgmt(c, p, c->uds_rw_port, msg,
&msg_ready))
- pr_err("uds port: management forward failed");
+
+ if ( forward_to_uds == 1 ) {
+ if (clock_do_forward_mgmt(c, p, c->uds_rw_port, msg,
&msg_ready))
+ pr_err("uds port: management forward failed");
+ }
+
+ /* If ingress port is uds port (pmc) then restore old sequence
count. */
+ if (p == c->uds_rw_port) msg->header.sequenceId =
temp_seq_count;
+
if (msg_ready) {
msg_post_recv(msg, pdulen);
msg->management.boundaryHops++;
--
2.17.1
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel