Signed-off-by: Martin Pecka <pecka...@fel.cvut.cz>
---
 clock.c             |  1 +
 config.c            |  2 ++
 port.c              | 10 ++++++++++
 port.h              | 14 ++++++++++++++
 ptp4l.8             | 10 ++++++++++
 transport.c         | 11 +++++++++++
 transport.h         | 15 +++++++++++++++
 transport_private.h |  1 +
 uds.c               |  5 ++++-
 9 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/clock.c b/clock.c
index f808b35..6cb0876 100644
--- a/clock.c
+++ b/clock.c
@@ -1232,6 +1232,7 @@ struct clock *clock_create(enum clock_type type, struct 
config *config,
                pr_err("failed to open the UDS-RO port");
                return NULL;
        }
+  port_set_uds_ro(c->uds_ro_port, true);
        clock_fda_changed(c);
 
        c->slave_event_monitor = monitor_create(config, c->uds_rw_port);
diff --git a/config.c b/config.c
index b4c16d8..24cef3d 100644
--- a/config.c
+++ b/config.c
@@ -35,6 +35,7 @@
 #include "util.h"
 
 #define UDS_FILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) /*0660*/
+#define UDS_RO_FILEMODE (UDS_FILEMODE|S_IROTH) /*0664*/
 
 struct interface {
        STAILQ_ENTRY(interface) list;
@@ -335,6 +336,7 @@ struct config_item config_tab[] = {
        GLOB_ITEM_STR("uds_address", "/var/run/ptp4l"),
        GLOB_ITEM_STR("uds_ro_address", "/var/run/ptp4lro"),
        PORT_ITEM_INT("uds_file_mode", UDS_FILEMODE, 0, 04777),
+       PORT_ITEM_INT("uds_ro_file_mode", UDS_RO_FILEMODE, 0, 04777),
        PORT_ITEM_INT("unicast_listen", 0, 0, 1),
        PORT_ITEM_INT("unicast_master_table", 0, 0, INT_MAX),
        PORT_ITEM_INT("unicast_req_duration", 3600, 10, INT_MAX),
diff --git a/port.c b/port.c
index f2b666c..a632d2b 100644
--- a/port.c
+++ b/port.c
@@ -3389,3 +3389,13 @@ enum bmca_select port_bmca(struct port *p)
 {
        return p->bmca;
 }
+
+bool port_is_uds_ro(struct port* p)
+{
+  return transport_is_uds_ro(p->trp);
+}
+
+void port_set_uds_ro(struct port* p, bool value)
+{
+  transport_set_uds_ro(p->trp, value);
+}
\ No newline at end of file
diff --git a/port.h b/port.h
index 37a4e19..cfe7e6b 100644
--- a/port.h
+++ b/port.h
@@ -350,4 +350,18 @@ enum bmca_select port_bmca(struct port *p);
  */
 void tc_cleanup(void);
 
+/**
+ * Whether this port is the UDS read-only port.
+ * @param p  A port instance.
+ * @return Whether this port is the UDS read-only port.
+ */
+bool port_is_uds_ro(struct port *p);
+
+/**
+ * Set whether this port is the UDS read-only port. 
+ * @param p      A port instance. 
+ * @param value  Value of the property.
+ */
+void port_set_uds_ro(struct port *p, bool value);
+
 #endif
diff --git a/ptp4l.8 b/ptp4l.8
index 71a414c..021dcad 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -648,6 +648,16 @@ management messages, which is restricted to GET actions 
and does not forward
 messages to other ports. Access to this socket can be given to untrusted
 applications for monitoring purposes. The default is /var/run/ptp4lro.
 .TP
+.B uds_file_mode
+File mode of the UNIX domain socket used for receiving local management
+messages. The mode should be specified as an octal number, i.e. it
+should start with a 0 literal. The default mode is 0660.
+.TP
+.B uds_ro_file_mode
+File mode of the second (read-only) UNIX domain socket used for receiving
+local management messages. The mode should be specified as an octal number,
+i.e. it should start with a 0 literal. The default mode is 0664.
+.TP
 .B dscp_event
 Defines the Differentiated Services Codepoint (DSCP) to be used for PTP
 event messages. Must be a value between 0 and 63. There are several media
diff --git a/transport.c b/transport.c
index 9366fbf..fe4a7c8 100644
--- a/transport.c
+++ b/transport.c
@@ -123,6 +123,7 @@ struct transport *transport_create(struct config *cfg,
        if (t) {
                t->type = type;
                t->cfg = cfg;
+    t->is_uds_ro = false;
        }
        return t;
 }
@@ -131,3 +132,13 @@ void transport_destroy(struct transport *t)
 {
        t->release(t);
 }
+
+bool transport_is_uds_ro(struct transport* t)
+{
+  return t->is_uds_ro;
+}
+
+void transport_set_uds_ro(struct transport* t, bool value)
+{
+  t->is_uds_ro = value;
+}
diff --git a/transport.h b/transport.h
index 7a7f87b..644a547 100644
--- a/transport.h
+++ b/transport.h
@@ -22,6 +22,7 @@
 
 #include <time.h>
 #include <inttypes.h>
+#include <stdbool.h>
 
 #include "fd.h"
 #include "msg.h"
@@ -153,4 +154,18 @@ struct transport *transport_create(struct config *cfg,
  */
 void transport_destroy(struct transport *t);
 
+/**
+ * Whether this transport belongs to a UDS read-only port.
+ * @param p  A port instance.
+ * @return Whether this transport belongs to a UDS read-only port.
+ */
+bool transport_is_uds_ro(struct transport *t);
+
+/**
+ * Set whether this transport belongs to a UDS read-only port. 
+ * @param t      A transport instance. 
+ * @param value  Value of the property.
+ */
+void transport_set_uds_ro(struct transport *t, bool value);
+
 #endif
diff --git a/transport_private.h b/transport_private.h
index ec28e47..4871b19 100644
--- a/transport_private.h
+++ b/transport_private.h
@@ -29,6 +29,7 @@
 struct transport {
        enum transport_type type;
        struct config *cfg;
+  bool is_uds_ro;
 
        int (*close)(struct transport *t, struct fdarray *fda);
 
diff --git a/uds.c b/uds.c
index 30a0f1e..f2502c0 100644
--- a/uds.c
+++ b/uds.c
@@ -56,7 +56,10 @@ static int uds_open(struct transport *t, struct interface 
*iface, struct fdarray
        char *uds_path = config_get_string(t->cfg, NULL, "uds_address");
        struct uds *uds = container_of(t, struct uds, t);
        const char *name = interface_name(iface);
-       mode_t file_mode = (mode_t)config_get_int(t->cfg, name, 
"uds_file_mode");
+  const char* file_mode_cfg = "uds_file_mode";
+  if (transport_is_uds_ro(t))
+    file_mode_cfg = "uds_ro_file_mode";
+       mode_t file_mode = (mode_t)config_get_int(t->cfg, name, file_mode_cfg);
        struct sockaddr_un sa;
        int fd, err;
 
-- 
2.17.1



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

Reply via email to