diff --git a/config.c b/config.c index 93ea5da..83cb48e 100644 --- a/config.c +++ b/config.c @@ -285,6 +285,7 @@ struct config_item config_tab[] = { GLOB_ITEM_INT("servo_num_offset_values", 10, 0, INT_MAX), GLOB_ITEM_INT("servo_offset_threshold", 0, 0, INT_MAX), GLOB_ITEM_INT("slaveOnly", 0, 0, 1), + GLOB_ITEM_INT("socket_priority", 0, 0, 15), GLOB_ITEM_DBL("step_threshold", 0.0, 0.0, DBL_MAX), GLOB_ITEM_INT("summary_interval", 0, INT_MIN, INT_MAX), PORT_ITEM_INT("syncReceiptTimeout", 0, 0, UINT8_MAX), diff --git a/configs/default.cfg b/configs/default.cfg index e23dfd7..c52dc37 100644 --- a/configs/default.cfg +++ b/configs/default.cfg @@ -4,6 +4,7 @@ # twoStepFlag 1 slaveOnly 0 +socket_priority 0 priority1 128 priority2 128 domainNumber 0 diff --git a/ptp4l.8 b/ptp4l.8 index 1a01108..ab156d9 100644 --- a/ptp4l.8 +++ b/ptp4l.8 @@ -384,6 +384,13 @@ The default is 1 (enabled). .B slaveOnly The local clock is a slave-only clock if enabled. The default is 0 (disabled). .TP +.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. +.TP .B gmCapable If this option is enabled, then the local clock is able to become grand master. This is only for use with 802.1AS clocks and has no effect on 1588 clocks. diff --git a/raw.c b/raw.c index 8dc50bc..f1c92b9 100644 --- a/raw.c +++ b/raw.c @@ -150,7 +150,7 @@ static int raw_close(struct transport *t, struct fdarray *fda) } static int open_socket(const char *name, int event, unsigned char *ptp_dst_mac, - unsigned char *p2p_dst_mac) + unsigned char *p2p_dst_mac, int socket_priority) { struct sockaddr_ll addr; int fd, index; @@ -176,6 +176,13 @@ static int open_socket(const char *name, int event, unsigned char *ptp_dst_mac, pr_err("setsockopt SO_BINDTODEVICE failed: %m"); goto no_option; } + + if (socket_priority > 0 && + setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &socket_priority, + sizeof(socket_priority))) { + pr_err("setsockopt SO_PRIORITY failed: %m"); + goto no_option; + } if (raw_configure(fd, event, index, ptp_dst_mac, p2p_dst_mac, 1)) goto no_option; @@ -205,7 +212,7 @@ static int raw_open(struct transport *t, struct interface *iface, struct raw *raw = container_of(t, struct raw, t); unsigned char ptp_dst_mac[MAC_LEN]; unsigned char p2p_dst_mac[MAC_LEN]; - int efd, gfd; + int efd, gfd, socket_priority; char *str, *name; name = iface->ts_label; @@ -225,11 +232,13 @@ static int raw_open(struct transport *t, struct interface *iface, if (sk_interface_macaddr(name, &raw->src_addr)) goto no_mac; - efd = open_socket(name, 1, ptp_dst_mac, p2p_dst_mac); + socket_priority = config_get_int(t->cfg, "global", "socket_priority"); + + efd = open_socket(name, 1, ptp_dst_mac, p2p_dst_mac, socket_priority); if (efd < 0) goto no_event; - gfd = open_socket(name, 0, ptp_dst_mac, p2p_dst_mac); + gfd = open_socket(name, 0, ptp_dst_mac, p2p_dst_mac, socket_priority); if (gfd < 0) goto no_general;