3b72dd
Patches backported from the upstream repository.
3b72dd
3b72dd
commit acc045034dd0db9dd4c4aca4b26528f8fed2ae78
3b72dd
Author: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
Date:   Thu Feb 11 16:47:08 2021 +0100
3b72dd
3b72dd
    port: Ignore non-management messages on UDS port.
3b72dd
    
3b72dd
    Drop non-management messages on the UDS port early in the processing to
3b72dd
    prevent them from changing the port or clock state.
3b72dd
    
3b72dd
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
3b72dd
diff --git a/port.c b/port.c
3b72dd
index fa49663..3fd06b1 100644
3b72dd
--- a/port.c
3b72dd
+++ b/port.c
3b72dd
@@ -56,6 +56,7 @@ enum syfu_event {
3b72dd
 };
3b72dd
 
3b72dd
 static int port_is_ieee8021as(struct port *p);
3b72dd
+static int port_is_uds(struct port *p);
3b72dd
 static void port_nrate_initialize(struct port *p);
3b72dd
 
3b72dd
 static int announce_compare(struct ptp_message *m1, struct ptp_message *m2)
3b72dd
@@ -691,6 +692,9 @@ static int port_ignore(struct port *p, struct ptp_message *m)
3b72dd
 {
3b72dd
 	struct ClockIdentity c1, c2;
3b72dd
 
3b72dd
+	if (port_is_uds(p) && msg_type(m) != MANAGEMENT) {
3b72dd
+		return 1;
3b72dd
+	}
3b72dd
 	if (incapable_ignore(p, m)) {
3b72dd
 		return 1;
3b72dd
 	}
3b72dd
@@ -771,6 +775,11 @@ static int port_is_ieee8021as(struct port *p)
3b72dd
 	return p->follow_up_info ? 1 : 0;
3b72dd
 }
3b72dd
 
3b72dd
+static int port_is_uds(struct port *p)
3b72dd
+{
3b72dd
+	return transport_type(p->trp) == TRANS_UDS;
3b72dd
+}
3b72dd
+
3b72dd
 static void port_management_send_error(struct port *p, struct port *ingress,
3b72dd
 				       struct ptp_message *msg, int error_id)
3b72dd
 {
3b72dd
3b72dd
commit 72ec806fa62a87cb7e5444e27fa6bdcbfe4e27ca
3b72dd
Author: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
Date:   Thu Feb 11 16:47:09 2021 +0100
3b72dd
3b72dd
    clock: Don't allow COMMAND action on non-UDS port.
3b72dd
    
3b72dd
    No COMMAND actions are currently supported, but check the port early in
3b72dd
    clock_manage() before reaching port_manage().
3b72dd
    
3b72dd
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
3b72dd
diff --git a/clock.c b/clock.c
3b72dd
index a66d189..a6947bc 100644
3b72dd
--- a/clock.c
3b72dd
+++ b/clock.c
3b72dd
@@ -1423,6 +1423,11 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
3b72dd
 			return changed;
3b72dd
 		break;
3b72dd
 	case COMMAND:
3b72dd
+		if (p != c->uds_port) {
3b72dd
+			/* Sorry, only allowed on the UDS port. */
3b72dd
+			clock_management_send_error(p, msg, TLV_NOT_SUPPORTED);
3b72dd
+			return changed;
3b72dd
+		}
3b72dd
 		break;
3b72dd
 	default:
3b72dd
 		return changed;
3b72dd
3b72dd
commit 2b45d80eadcb81c8bdf45baf98dabeebd912b1b0
3b72dd
Author: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
Date:   Thu Feb 11 16:47:10 2021 +0100
3b72dd
3b72dd
    clock: Rename UDS variables to read-write.
3b72dd
    
3b72dd
    In preparation for a new read-only UDS port, rename variables of the
3b72dd
    current UDS port to make it clear it is read-write, as opposed to
3b72dd
    read-only.
3b72dd
    
3b72dd
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
3b72dd
diff --git a/clock.c b/clock.c
3b72dd
index a6947bc..d013b19 100644
3b72dd
--- a/clock.c
3b72dd
+++ b/clock.c
3b72dd
@@ -95,7 +95,7 @@ struct clock {
3b72dd
 	struct foreign_clock *best;
3b72dd
 	struct ClockIdentity best_id;
3b72dd
 	LIST_HEAD(ports_head, port) ports;
3b72dd
-	struct port *uds_port;
3b72dd
+	struct port *uds_rw_port;
3b72dd
 	struct pollfd *pollfd;
3b72dd
 	int pollfd_valid;
3b72dd
 	int nports; /* does not include the UDS port */
3b72dd
@@ -129,7 +129,7 @@ struct clock {
3b72dd
 	struct clock_stats stats;
3b72dd
 	int stats_interval;
3b72dd
 	struct clockcheck *sanity_check;
3b72dd
-	struct interface *udsif;
3b72dd
+	struct interface *uds_rw_if;
3b72dd
 	LIST_HEAD(clock_subscribers_head, clock_subscriber) subscribers;
3b72dd
 	struct monitor *slave_event_monitor;
3b72dd
 };
3b72dd
@@ -245,7 +245,7 @@ void clock_send_notification(struct clock *c, struct ptp_message *msg,
3b72dd
 {
3b72dd
 	unsigned int event_pos = event / 8;
3b72dd
 	uint8_t mask = 1 << (event % 8);
3b72dd
-	struct port *uds = c->uds_port;
3b72dd
+	struct port *uds = c->uds_rw_port;
3b72dd
 	struct clock_subscriber *s;
3b72dd
 
3b72dd
 	LIST_FOREACH(s, &c->subscribers, list) {
3b72dd
@@ -267,13 +267,13 @@ void clock_destroy(struct clock *c)
3b72dd
 {
3b72dd
 	struct port *p, *tmp;
3b72dd
 
3b72dd
-	interface_destroy(c->udsif);
3b72dd
+	interface_destroy(c->uds_rw_if);
3b72dd
 	clock_flush_subscriptions(c);
3b72dd
 	LIST_FOREACH_SAFE(p, &c->ports, list, tmp) {
3b72dd
 		clock_remove_port(c, p);
3b72dd
 	}
3b72dd
 	monitor_destroy(c->slave_event_monitor);
3b72dd
-	port_close(c->uds_port);
3b72dd
+	port_close(c->uds_rw_port);
3b72dd
 	free(c->pollfd);
3b72dd
 	if (c->clkid != CLOCK_REALTIME) {
3b72dd
 		phc_close(c->clkid);
3b72dd
@@ -442,7 +442,7 @@ static int clock_management_fill_response(struct clock *c, struct port *p,
3b72dd
 		datalen = sizeof(*gsn);
3b72dd
 		break;
3b72dd
 	case TLV_SUBSCRIBE_EVENTS_NP:
3b72dd
-		if (p != c->uds_port) {
3b72dd
+		if (p != c->uds_rw_port) {
3b72dd
 			/* Only the UDS port allowed. */
3b72dd
 			break;
3b72dd
 		}
3b72dd
@@ -784,7 +784,7 @@ static int forwarding(struct clock *c, struct port *p)
3b72dd
 	default:
3b72dd
 		break;
3b72dd
 	}
3b72dd
-	if (p == c->uds_port && ps != PS_FAULTY) {
3b72dd
+	if (p == c->uds_rw_port && ps != PS_FAULTY) {
3b72dd
 		return 1;
3b72dd
 	}
3b72dd
 	return 0;
3b72dd
@@ -1044,20 +1044,20 @@ struct clock *clock_create(enum clock_type type, struct config *config,
3b72dd
 
3b72dd
 	/* Configure the UDS. */
3b72dd
 	uds_ifname = config_get_string(config, NULL, "uds_address");
3b72dd
-	c->udsif = interface_create(uds_ifname);
3b72dd
-	if (config_set_section_int(config, interface_name(c->udsif),
3b72dd
+	c->uds_rw_if = interface_create(uds_ifname);
3b72dd
+	if (config_set_section_int(config, interface_name(c->uds_rw_if),
3b72dd
 				   "announceReceiptTimeout", 0)) {
3b72dd
 		return NULL;
3b72dd
 	}
3b72dd
-	if (config_set_section_int(config, interface_name(c->udsif),
3b72dd
+	if (config_set_section_int(config, interface_name(c->uds_rw_if),
3b72dd
 				    "delay_mechanism", DM_AUTO)) {
3b72dd
 		return NULL;
3b72dd
 	}
3b72dd
-	if (config_set_section_int(config, interface_name(c->udsif),
3b72dd
+	if (config_set_section_int(config, interface_name(c->uds_rw_if),
3b72dd
 				    "network_transport", TRANS_UDS)) {
3b72dd
 		return NULL;
3b72dd
 	}
3b72dd
-	if (config_set_section_int(config, interface_name(c->udsif),
3b72dd
+	if (config_set_section_int(config, interface_name(c->uds_rw_if),
3b72dd
 				   "delay_filter_length", 1)) {
3b72dd
 		return NULL;
3b72dd
 	}
3b72dd
@@ -1180,14 +1180,15 @@ struct clock *clock_create(enum clock_type type, struct config *config,
3b72dd
 	}
3b72dd
 
3b72dd
 	/* Create the UDS interface. */
3b72dd
-	c->uds_port = port_open(phc_device, phc_index, timestamping, 0, c->udsif, c);
3b72dd
-	if (!c->uds_port) {
3b72dd
+	c->uds_rw_port = port_open(phc_device, phc_index, timestamping, 0,
3b72dd
+				   c->uds_rw_if, c);
3b72dd
+	if (!c->uds_rw_port) {
3b72dd
 		pr_err("failed to open the UDS port");
3b72dd
 		return NULL;
3b72dd
 	}
3b72dd
 	clock_fda_changed(c);
3b72dd
 
3b72dd
-	c->slave_event_monitor = monitor_create(config, c->uds_port);
3b72dd
+	c->slave_event_monitor = monitor_create(config, c->uds_rw_port);
3b72dd
 	if (!c->slave_event_monitor) {
3b72dd
 		pr_err("failed to create slave event monitor");
3b72dd
 		return NULL;
3b72dd
@@ -1206,7 +1207,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
3b72dd
 	LIST_FOREACH(p, &c->ports, list) {
3b72dd
 		port_dispatch(p, EV_INITIALIZE, 0);
3b72dd
 	}
3b72dd
-	port_dispatch(c->uds_port, EV_INITIALIZE, 0);
3b72dd
+	port_dispatch(c->uds_rw_port, EV_INITIALIZE, 0);
3b72dd
 
3b72dd
 	return c;
3b72dd
 }
3b72dd
@@ -1314,7 +1315,7 @@ static void clock_check_pollfd(struct clock *c)
3b72dd
 		clock_fill_pollfd(dest, p);
3b72dd
 		dest += N_CLOCK_PFD;
3b72dd
 	}
3b72dd
-	clock_fill_pollfd(dest, c->uds_port);
3b72dd
+	clock_fill_pollfd(dest, c->uds_rw_port);
3b72dd
 	c->pollfd_valid = 1;
3b72dd
 }
3b72dd
 
3b72dd
@@ -1331,7 +1332,7 @@ static int clock_do_forward_mgmt(struct clock *c,
3b72dd
 		return 0;
3b72dd
 
3b72dd
 	/* Don't forward any requests to the UDS port. */
3b72dd
-	if (out == c->uds_port) {
3b72dd
+	if (out == c->uds_rw_port) {
3b72dd
 		switch (management_action(msg)) {
3b72dd
 		case GET:
3b72dd
 		case SET:
3b72dd
@@ -1362,7 +1363,7 @@ static void clock_forward_mgmt_msg(struct clock *c, struct port *p, struct ptp_m
3b72dd
 				pr_err("port %d: management forward failed",
3b72dd
 				       port_number(piter));
3b72dd
 		}
3b72dd
-		if (clock_do_forward_mgmt(c, p, c->uds_port, msg, &msg_ready))
3b72dd
+		if (clock_do_forward_mgmt(c, p, c->uds_rw_port, msg, &msg_ready))
3b72dd
 			pr_err("uds port: management forward failed");
3b72dd
 		if (msg_ready) {
3b72dd
 			msg_post_recv(msg, pdulen);
3b72dd
@@ -1414,7 +1415,7 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
3b72dd
 			clock_management_send_error(p, msg, TLV_WRONG_LENGTH);
3b72dd
 			return changed;
3b72dd
 		}
3b72dd
-		if (p != c->uds_port) {
3b72dd
+		if (p != c->uds_rw_port) {
3b72dd
 			/* Sorry, only allowed on the UDS port. */
3b72dd
 			clock_management_send_error(p, msg, TLV_NOT_SUPPORTED);
3b72dd
 			return changed;
3b72dd
@@ -1423,7 +1424,7 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
3b72dd
 			return changed;
3b72dd
 		break;
3b72dd
 	case COMMAND:
3b72dd
-		if (p != c->uds_port) {
3b72dd
+		if (p != c->uds_rw_port) {
3b72dd
 			/* Sorry, only allowed on the UDS port. */
3b72dd
 			clock_management_send_error(p, msg, TLV_NOT_SUPPORTED);
3b72dd
 			return changed;
3b72dd
@@ -1435,7 +1436,7 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
3b72dd
 
3b72dd
 	switch (mgt->id) {
3b72dd
 	case TLV_PORT_PROPERTIES_NP:
3b72dd
-		if (p != c->uds_port) {
3b72dd
+		if (p != c->uds_rw_port) {
3b72dd
 			/* Only the UDS port allowed. */
3b72dd
 			clock_management_send_error(p, msg, TLV_NOT_SUPPORTED);
3b72dd
 			return 0;
3b72dd
@@ -1500,7 +1501,7 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
3b72dd
 
3b72dd
 void clock_notify_event(struct clock *c, enum notification event)
3b72dd
 {
3b72dd
-	struct port *uds = c->uds_port;
3b72dd
+	struct port *uds = c->uds_rw_port;
3b72dd
 	struct PortIdentity pid = port_identity(uds);
3b72dd
 	struct ptp_message *msg;
3b72dd
 	int id;
3b72dd
@@ -1604,7 +1605,7 @@ int clock_poll(struct clock *c)
3b72dd
 	/* Check the UDS port. */
3b72dd
 	for (i = 0; i < N_POLLFD; i++) {
3b72dd
 		if (cur[i].revents & (POLLIN|POLLPRI)) {
3b72dd
-			event = port_event(c->uds_port, i);
3b72dd
+			event = port_event(c->uds_rw_port, i);
3b72dd
 			if (EV_STATE_DECISION_EVENT == event) {
3b72dd
 				c->sde = 1;
3b72dd
 			}
3b72dd
3b72dd
commit 1f74a16502b55ce8eaed3d7488542e5469ac8263
3b72dd
Author: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
Date:   Thu Feb 11 16:47:11 2021 +0100
3b72dd
3b72dd
    clock: Add read-only UDS port for monitoring.
3b72dd
    
3b72dd
    Add a second UDS port to allow untrusted applications to monitor ptp4l.
3b72dd
    On this "read-only" UDS port disable non-GET actions and forwarding.
3b72dd
    The path can be configured with the uds_ro_address option (default is
3b72dd
    /var/run/ptp4lro).
3b72dd
    
3b72dd
    Forwarding is disabled to limit the access to the local ptp4l instance.
3b72dd
    
3b72dd
    Subscriptions are not enabled to prevent the applications from making a
3b72dd
    large number of subscriptions or interfere with applications that have
3b72dd
    access to the read-write UDS port.
3b72dd
    
3b72dd
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
3b72dd
diff --git a/clock.c b/clock.c
3b72dd
index d013b19..8592d29 100644
3b72dd
--- a/clock.c
3b72dd
+++ b/clock.c
3b72dd
@@ -96,9 +96,10 @@ struct clock {
3b72dd
 	struct ClockIdentity best_id;
3b72dd
 	LIST_HEAD(ports_head, port) ports;
3b72dd
 	struct port *uds_rw_port;
3b72dd
+	struct port *uds_ro_port;
3b72dd
 	struct pollfd *pollfd;
3b72dd
 	int pollfd_valid;
3b72dd
-	int nports; /* does not include the UDS port */
3b72dd
+	int nports; /* does not include the two UDS ports */
3b72dd
 	int last_port_number;
3b72dd
 	int sde;
3b72dd
 	int free_running;
3b72dd
@@ -130,6 +131,7 @@ struct clock {
3b72dd
 	int stats_interval;
3b72dd
 	struct clockcheck *sanity_check;
3b72dd
 	struct interface *uds_rw_if;
3b72dd
+	struct interface *uds_ro_if;
3b72dd
 	LIST_HEAD(clock_subscribers_head, clock_subscriber) subscribers;
3b72dd
 	struct monitor *slave_event_monitor;
3b72dd
 };
3b72dd
@@ -268,12 +270,14 @@ void clock_destroy(struct clock *c)
3b72dd
 	struct port *p, *tmp;
3b72dd
 
3b72dd
 	interface_destroy(c->uds_rw_if);
3b72dd
+	interface_destroy(c->uds_ro_if);
3b72dd
 	clock_flush_subscriptions(c);
3b72dd
 	LIST_FOREACH_SAFE(p, &c->ports, list, tmp) {
3b72dd
 		clock_remove_port(c, p);
3b72dd
 	}
3b72dd
 	monitor_destroy(c->slave_event_monitor);
3b72dd
 	port_close(c->uds_rw_port);
3b72dd
+	port_close(c->uds_ro_port);
3b72dd
 	free(c->pollfd);
3b72dd
 	if (c->clkid != CLOCK_REALTIME) {
3b72dd
 		phc_close(c->clkid);
3b72dd
@@ -443,7 +447,7 @@ static int clock_management_fill_response(struct clock *c, struct port *p,
3b72dd
 		break;
3b72dd
 	case TLV_SUBSCRIBE_EVENTS_NP:
3b72dd
 		if (p != c->uds_rw_port) {
3b72dd
-			/* Only the UDS port allowed. */
3b72dd
+			/* Only the UDS-RW port allowed. */
3b72dd
 			break;
3b72dd
 		}
3b72dd
 		sen = (struct subscribe_events_np *)tlv->data;
3b72dd
@@ -774,6 +778,10 @@ static int clock_utc_correct(struct clock *c, tmv_t ingress)
3b72dd
 static int forwarding(struct clock *c, struct port *p)
3b72dd
 {
3b72dd
 	enum port_state ps = port_state(p);
3b72dd
+
3b72dd
+	if (p == c->uds_ro_port)
3b72dd
+		return 0;
3b72dd
+
3b72dd
 	switch (ps) {
3b72dd
 	case PS_MASTER:
3b72dd
 	case PS_GRAND_MASTER:
3b72dd
@@ -818,7 +826,7 @@ static int clock_add_port(struct clock *c, const char *phc_device,
3b72dd
 {
3b72dd
 	struct port *p, *piter, *lastp = NULL;
3b72dd
 
3b72dd
-	if (clock_resize_pollfd(c, c->nports + 1)) {
3b72dd
+	if (clock_resize_pollfd(c, c->nports + 2)) {
3b72dd
 		return -1;
3b72dd
 	}
3b72dd
 	p = port_open(phc_device, phc_index, timestamping,
3b72dd
@@ -1043,6 +1051,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
3b72dd
 	}
3b72dd
 
3b72dd
 	/* Configure the UDS. */
3b72dd
+
3b72dd
 	uds_ifname = config_get_string(config, NULL, "uds_address");
3b72dd
 	c->uds_rw_if = interface_create(uds_ifname);
3b72dd
 	if (config_set_section_int(config, interface_name(c->uds_rw_if),
3b72dd
@@ -1062,6 +1071,25 @@ struct clock *clock_create(enum clock_type type, struct config *config,
3b72dd
 		return NULL;
3b72dd
 	}
3b72dd
 
3b72dd
+	uds_ifname = config_get_string(config, NULL, "uds_ro_address");
3b72dd
+	c->uds_ro_if = interface_create(uds_ifname);
3b72dd
+	if (config_set_section_int(config, interface_name(c->uds_ro_if),
3b72dd
+				   "announceReceiptTimeout", 0)) {
3b72dd
+		return NULL;
3b72dd
+	}
3b72dd
+	if (config_set_section_int(config, interface_name(c->uds_ro_if),
3b72dd
+				   "delay_mechanism", DM_AUTO)) {
3b72dd
+		return NULL;
3b72dd
+	}
3b72dd
+	if (config_set_section_int(config, interface_name(c->uds_ro_if),
3b72dd
+				   "network_transport", TRANS_UDS)) {
3b72dd
+		return NULL;
3b72dd
+	}
3b72dd
+	if (config_set_section_int(config, interface_name(c->uds_ro_if),
3b72dd
+				   "delay_filter_length", 1)) {
3b72dd
+		return NULL;
3b72dd
+	}
3b72dd
+
3b72dd
 	c->config = config;
3b72dd
 	c->free_running = config_get_int(config, NULL, "free_running");
3b72dd
 	c->freq_est_interval = config_get_int(config, NULL, "freq_est_interval");
3b72dd
@@ -1179,11 +1207,18 @@ struct clock *clock_create(enum clock_type type, struct config *config,
3b72dd
 		return NULL;
3b72dd
 	}
3b72dd
 
3b72dd
-	/* Create the UDS interface. */
3b72dd
+	/* Create the UDS interfaces. */
3b72dd
+
3b72dd
 	c->uds_rw_port = port_open(phc_device, phc_index, timestamping, 0,
3b72dd
 				   c->uds_rw_if, c);
3b72dd
 	if (!c->uds_rw_port) {
3b72dd
-		pr_err("failed to open the UDS port");
3b72dd
+		pr_err("failed to open the UDS-RW port");
3b72dd
+		return NULL;
3b72dd
+	}
3b72dd
+	c->uds_ro_port = port_open(phc_device, phc_index, timestamping, 0,
3b72dd
+				   c->uds_ro_if, c);
3b72dd
+	if (!c->uds_ro_port) {
3b72dd
+		pr_err("failed to open the UDS-RO port");
3b72dd
 		return NULL;
3b72dd
 	}
3b72dd
 	clock_fda_changed(c);
3b72dd
@@ -1208,6 +1243,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
3b72dd
 		port_dispatch(p, EV_INITIALIZE, 0);
3b72dd
 	}
3b72dd
 	port_dispatch(c->uds_rw_port, EV_INITIALIZE, 0);
3b72dd
+	port_dispatch(c->uds_ro_port, EV_INITIALIZE, 0);
3b72dd
 
3b72dd
 	return c;
3b72dd
 }
3b72dd
@@ -1278,9 +1314,9 @@ static int clock_resize_pollfd(struct clock *c, int new_nports)
3b72dd
 {
3b72dd
 	struct pollfd *new_pollfd;
3b72dd
 
3b72dd
-	/* Need to allocate one whole extra block of fds for UDS. */
3b72dd
+	/* Need to allocate two whole extra blocks of fds for UDS ports. */
3b72dd
 	new_pollfd = realloc(c->pollfd,
3b72dd
-			     (new_nports + 1) * N_CLOCK_PFD *
3b72dd
+			     (new_nports + 2) * N_CLOCK_PFD *
3b72dd
 			     sizeof(struct pollfd));
3b72dd
 	if (!new_pollfd) {
3b72dd
 		return -1;
3b72dd
@@ -1316,6 +1352,8 @@ static void clock_check_pollfd(struct clock *c)
3b72dd
 		dest += N_CLOCK_PFD;
3b72dd
 	}
3b72dd
 	clock_fill_pollfd(dest, c->uds_rw_port);
3b72dd
+	dest += N_CLOCK_PFD;
3b72dd
+	clock_fill_pollfd(dest, c->uds_ro_port);
3b72dd
 	c->pollfd_valid = 1;
3b72dd
 }
3b72dd
 
3b72dd
@@ -1331,7 +1369,8 @@ static int clock_do_forward_mgmt(struct clock *c,
3b72dd
 	if (in == out || !forwarding(c, out))
3b72dd
 		return 0;
3b72dd
 
3b72dd
-	/* Don't forward any requests to the UDS port. */
3b72dd
+	/* Don't forward any requests to the UDS-RW port
3b72dd
+	   (the UDS-RO port doesn't allow any forwarding). */
3b72dd
 	if (out == c->uds_rw_port) {
3b72dd
 		switch (management_action(msg)) {
3b72dd
 		case GET:
3b72dd
@@ -1416,7 +1455,7 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
3b72dd
 			return changed;
3b72dd
 		}
3b72dd
 		if (p != c->uds_rw_port) {
3b72dd
-			/* Sorry, only allowed on the UDS port. */
3b72dd
+			/* Sorry, only allowed on the UDS-RW port. */
3b72dd
 			clock_management_send_error(p, msg, TLV_NOT_SUPPORTED);
3b72dd
 			return changed;
3b72dd
 		}
3b72dd
@@ -1425,7 +1464,7 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
3b72dd
 		break;
3b72dd
 	case COMMAND:
3b72dd
 		if (p != c->uds_rw_port) {
3b72dd
-			/* Sorry, only allowed on the UDS port. */
3b72dd
+			/* Sorry, only allowed on the UDS-RW port. */
3b72dd
 			clock_management_send_error(p, msg, TLV_NOT_SUPPORTED);
3b72dd
 			return changed;
3b72dd
 		}
3b72dd
@@ -1437,7 +1476,7 @@ int clock_manage(struct clock *c, struct port *p, struct ptp_message *msg)
3b72dd
 	switch (mgt->id) {
3b72dd
 	case TLV_PORT_PROPERTIES_NP:
3b72dd
 		if (p != c->uds_rw_port) {
3b72dd
-			/* Only the UDS port allowed. */
3b72dd
+			/* Only the UDS-RW port allowed. */
3b72dd
 			clock_management_send_error(p, msg, TLV_NOT_SUPPORTED);
3b72dd
 			return 0;
3b72dd
 		}
3b72dd
@@ -1548,7 +1587,7 @@ int clock_poll(struct clock *c)
3b72dd
 	struct port *p;
3b72dd
 
3b72dd
 	clock_check_pollfd(c);
3b72dd
-	cnt = poll(c->pollfd, (c->nports + 1) * N_CLOCK_PFD, -1);
3b72dd
+	cnt = poll(c->pollfd, (c->nports + 2) * N_CLOCK_PFD, -1);
3b72dd
 	if (cnt < 0) {
3b72dd
 		if (EINTR == errno) {
3b72dd
 			return 0;
3b72dd
@@ -1602,7 +1641,7 @@ int clock_poll(struct clock *c)
3b72dd
 		cur += N_CLOCK_PFD;
3b72dd
 	}
3b72dd
 
3b72dd
-	/* Check the UDS port. */
3b72dd
+	/* Check the UDS ports. */
3b72dd
 	for (i = 0; i < N_POLLFD; i++) {
3b72dd
 		if (cur[i].revents & (POLLIN|POLLPRI)) {
3b72dd
 			event = port_event(c->uds_rw_port, i);
3b72dd
@@ -1611,6 +1650,13 @@ int clock_poll(struct clock *c)
3b72dd
 			}
3b72dd
 		}
3b72dd
 	}
3b72dd
+	cur += N_CLOCK_PFD;
3b72dd
+	for (i = 0; i < N_POLLFD; i++) {
3b72dd
+		if (cur[i].revents & (POLLIN|POLLPRI)) {
3b72dd
+			event = port_event(c->uds_ro_port, i);
3b72dd
+			/* sde is not expected on the UDS-RO port */
3b72dd
+		}
3b72dd
+	}
3b72dd
 
3b72dd
 	if (c->sde) {
3b72dd
 		handle_state_decision_event(c);
3b72dd
diff --git a/config.c b/config.c
3b72dd
index d237de9..96a5351 100644
3b72dd
--- a/config.c
3b72dd
+++ b/config.c
3b72dd
@@ -323,6 +323,7 @@ struct config_item config_tab[] = {
3b72dd
 	PORT_ITEM_INT("udp_ttl", 1, 1, 255),
3b72dd
 	PORT_ITEM_INT("udp6_scope", 0x0E, 0x00, 0x0F),
3b72dd
 	GLOB_ITEM_STR("uds_address", "/var/run/ptp4l"),
3b72dd
+	GLOB_ITEM_STR("uds_ro_address", "/var/run/ptp4lro"),
3b72dd
 	PORT_ITEM_INT("unicast_listen", 0, 0, 1),
3b72dd
 	PORT_ITEM_INT("unicast_master_table", 0, 0, INT_MAX),
3b72dd
 	PORT_ITEM_INT("unicast_req_duration", 3600, 10, INT_MAX),
3b72dd
diff --git a/configs/default.cfg b/configs/default.cfg
3b72dd
index 8c19129..d5bab7d 100644
3b72dd
--- a/configs/default.cfg
3b72dd
+++ b/configs/default.cfg
3b72dd
@@ -90,6 +90,7 @@ p2p_dst_mac		01:80:C2:00:00:0E
3b72dd
 udp_ttl			1
3b72dd
 udp6_scope		0x0E
3b72dd
 uds_address		/var/run/ptp4l
3b72dd
+uds_ro_address		/var/run/ptp4lro
3b72dd
 #
3b72dd
 # Default interface options
3b72dd
 #
3b72dd
diff --git a/ptp4l.8 b/ptp4l.8
3b72dd
index b179b81..f9bd228 100644
3b72dd
--- a/ptp4l.8
3b72dd
+++ b/ptp4l.8
3b72dd
@@ -615,6 +615,12 @@ is only relevant with IPv6 transport.  See RFC 4291.  The default is
3b72dd
 Specifies the address of the UNIX domain socket for receiving local
3b72dd
 management messages. The default is /var/run/ptp4l.
3b72dd
 .TP
3b72dd
+.B uds_ro_address
3b72dd
+Specifies the address of the second UNIX domain socket for receiving local
3b72dd
+management messages, which is restricted to GET actions and does not forward
3b72dd
+messages to other ports. Access to this socket can be given to untrusted
3b72dd
+applications for monitoring purposes. The default is /var/run/ptp4lro.
3b72dd
+.TP
3b72dd
 .B dscp_event
3b72dd
 Defines the Differentiated Services Codepoint (DSCP) to be used for PTP
3b72dd
 event messages. Must be a value between 0 and 63. There are several media
3b72dd
3b72dd
commit d4c5343237588d265c605f3772337bc88cabe787
3b72dd
Author: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
Date:   Thu Feb 11 16:47:12 2021 +0100
3b72dd
3b72dd
    timemaster: Set uds_ro_address for ptp4l instances.
3b72dd
    
3b72dd
    This prevents conflicts on the new UDS-RO port.
3b72dd
    
3b72dd
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
3b72dd
3b72dd
diff --git a/timemaster.c b/timemaster.c
3b72dd
index 00db59f..02408d6 100644
3b72dd
--- a/timemaster.c
3b72dd
+++ b/timemaster.c
3b72dd
@@ -712,7 +712,7 @@ static int add_ptp_source(struct ptp_domain *source,
3b72dd
 			  char **ntp_config, struct script *script)
3b72dd
 {
3b72dd
 	struct config_file *config_file;
3b72dd
-	char **command, *uds_path, **interfaces, *message_tag;
3b72dd
+	char **command, *uds_path, *uds_path2, **interfaces, *message_tag;
3b72dd
 	char ts_interface[IF_NAMESIZE];
3b72dd
 	int i, j, num_interfaces, *phc, *phcs, hw_ts, sw_ts;
3b72dd
 	struct sk_ts_info ts_info;
3b72dd
@@ -809,6 +809,8 @@ static int add_ptp_source(struct ptp_domain *source,
3b72dd
 
3b72dd
 		uds_path = string_newf("%s/ptp4l.%d.socket",
3b72dd
 				       config->rundir, *shm_segment);
3b72dd
+		uds_path2 = string_newf("%s/ptp4lro.%d.socket",
3b72dd
+					config->rundir, *shm_segment);
3b72dd
 
3b72dd
 		message_tag = string_newf("[%d", source->domain);
3b72dd
 		for (j = 0; interfaces[j]; j++)
3b72dd
@@ -832,8 +834,10 @@ static int add_ptp_source(struct ptp_domain *source,
3b72dd
 			       "slaveOnly 1\n"
3b72dd
 			       "domainNumber %d\n"
3b72dd
 			       "uds_address %s\n"
3b72dd
+			       "uds_ro_address %s\n"
3b72dd
 			       "message_tag %s\n",
3b72dd
-			       source->domain, uds_path, message_tag);
3b72dd
+			       source->domain, uds_path, uds_path2,
3b72dd
+			       message_tag);
3b72dd
 
3b72dd
 		if (phcs[i] >= 0) {
3b72dd
 			/* HW time stamping */
3b72dd
@@ -868,6 +872,7 @@ static int add_ptp_source(struct ptp_domain *source,
3b72dd
 
3b72dd
 		free(message_tag);
3b72dd
 		free(uds_path);
3b72dd
+		free(uds_path2);
3b72dd
 		free(interfaces);
3b72dd
 	}
3b72dd