ptp4l supports setting of socket priority. This is useful for traffic shaping e.g., utilizing Tx steering using TAPRIO or mqprio Qdisc or VLAN egress mappings.
However, that's only implemented for Layer 2 transport. Extend this for UDPv4 and UDPv6 transports. Update the man page accordingly. Note for UPDv4: The socket option call has to be performed after the DSCP QoS configuration, because the latter also configures the socket priority to an appropriate value chosen by the kernel. However, that's not necessarily the socket priority the user wants to have. In case the socket priority is not explicitly given, no operation is performed. Signed-off-by: Kurt Kanzenbach <k...@linutronix.de> --- RESEND, because I had to subscribe to the mailing list. ptp4l.8 | 6 +++--- udp.c | 15 ++++++++++++++- udp6.c | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ptp4l.8 b/ptp4l.8 index 12688028300f..f0a8f534222b 100644 --- a/ptp4l.8 +++ b/ptp4l.8 @@ -408,9 +408,9 @@ Use "clientOnly" instead. .B socket_priority Configure the SO_PRIORITY of sockets. This is to support cases where a user wants to route ptp4l traffic using Linux qdiscs for the purpose of traffic -shaping. This option is only available with the IEEE 802.3 transport (the -\fB-2\fP option) and is silently ignored when using the UDP IPv4/6 network -transports. Must be in the range of 0 to 15, inclusive. The default is 0. +shaping. This option is available with the IEEE 802.3 transport and UDP IPv4/6 +network transports. Must be in the range of 0 to 15, inclusive. The default is +0. .TP .B gmCapable If this option is enabled, then the local clock is able to become grand master. diff --git a/udp.c b/udp.c index 7c9402ea5283..7982cf87dee9 100644 --- a/udp.c +++ b/udp.c @@ -155,8 +155,8 @@ static int udp_open(struct transport *t, struct interface *iface, { struct udp *udp = container_of(t, struct udp, t); const char *name = interface_name(iface); + int efd, gfd, ttl, socket_priority; uint8_t event_dscp, general_dscp; - int efd, gfd, ttl; ttl = config_get_int(t->cfg, name, "udp_ttl"); udp->mac.len = 0; @@ -196,6 +196,19 @@ static int udp_open(struct transport *t, struct interface *iface, pr_warning("Failed to set general DSCP priority."); } + socket_priority = config_get_int(t->cfg, "global", "socket_priority"); + + if (socket_priority && + setsockopt(efd, SOL_SOCKET, SO_PRIORITY, &socket_priority, + sizeof(socket_priority))) { + pr_warning("Failed to set event socket priority."); + } + if (socket_priority && + setsockopt(gfd, SOL_SOCKET, SO_PRIORITY, &socket_priority, + sizeof(socket_priority))) { + pr_warning("Failed to set general socket priority."); + } + fda->fd[FD_EVENT] = efd; fda->fd[FD_GENERAL] = gfd; return 0; diff --git a/udp6.c b/udp6.c index bde1710b9e1a..414fcae623d2 100644 --- a/udp6.c +++ b/udp6.c @@ -165,8 +165,8 @@ static int udp6_open(struct transport *t, struct interface *iface, { struct udp6 *udp6 = container_of(t, struct udp6, t); const char *name = interface_name(iface); + int efd, gfd, hop_limit, socket_priority; uint8_t event_dscp, general_dscp; - int efd, gfd, hop_limit; hop_limit = config_get_int(t->cfg, name, "udp_ttl"); udp6->mac.len = 0; @@ -213,6 +213,19 @@ static int udp6_open(struct transport *t, struct interface *iface, pr_warning("Failed to set general DSCP priority."); } + socket_priority = config_get_int(t->cfg, "global", "socket_priority"); + + if (socket_priority && + setsockopt(efd, SOL_SOCKET, SO_PRIORITY, &socket_priority, + sizeof(socket_priority))) { + pr_warning("Failed to set event socket priority."); + } + if (socket_priority && + setsockopt(gfd, SOL_SOCKET, SO_PRIORITY, &socket_priority, + sizeof(socket_priority))) { + pr_warning("Failed to set general socket priority."); + } + fda->fd[FD_EVENT] = efd; fda->fd[FD_GENERAL] = gfd; return 0; -- 2.37.2 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel