diff --git a/config.c b/config.c index 883894b..57d5f4f 100644 --- a/config.c +++ b/config.c @@ -265,6 +265,7 @@ struct config_item config_tab[] = { PORT_ITEM_INT("udp_ttl", 1, 1, 255), PORT_ITEM_INT("udp6_scope", 0x0E, 0x00, 0x0F), GLOB_ITEM_STR("uds_address", "/var/run/ptp4l"), + 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), GLOB_ITEM_INT("use_syslog", 1, 0, 1), diff --git a/configs/default.cfg b/configs/default.cfg index 33c808e..00ec61f 100644 --- a/configs/default.cfg +++ b/configs/default.cfg @@ -42,6 +42,7 @@ hybrid_e2e 0 net_sync_monitor 0 tc_spanning_tree 0 tx_timestamp_timeout 1 +unicast_listen 0 unicast_master_table 0 unicast_req_duration 3600 use_syslog 1 diff --git a/port.c b/port.c index 8b12c3b..fea60db 100644 --- a/port.c +++ b/port.c @@ -41,6 +41,7 @@ #include "tmv.h" #include "tsproc.h" #include "unicast_client.h" +#include "unicast_service.h" #include "util.h" #define ALLOWED_LOST_RESPONSES 3 @@ -2212,6 +2213,7 @@ void port_close(struct port *p) rtnl_close(p->fda.fd[FD_RTNL]); } + unicast_service_cleanup(p); transport_destroy(p->trp); tsproc_destroy(p->tsproc); if (p->fault_fd >= 0) { @@ -2476,7 +2478,7 @@ static enum fsm_event bc_event(struct port *p, int fd_index) case FD_UNICAST_SRV_TIMER: pr_debug("port %hu: unicast service timeout", portnum(p)); - return EV_NONE; + return unicast_service_timer(p) ? EV_FAULT_DETECTED : EV_NONE; case FD_UNICAST_REQ_TIMER: pr_debug("port %hu: unicast request timeout", portnum(p)); @@ -2892,6 +2894,9 @@ struct port *port_open(int phc_index, config_set_section_int(cfg, p->name, "hybrid_e2e", 1)) { goto err_port; } + if (number && unicast_service_initialize(p)) { + goto err_port; + } p->hybrid_e2e = config_get_int(cfg, p->name, "hybrid_e2e"); if (number && type == CLOCK_TYPE_P2P && p->delayMechanism != DM_P2P) { diff --git a/port_signaling.c b/port_signaling.c index c26e062..f845d36 100644 --- a/port_signaling.c +++ b/port_signaling.c @@ -19,6 +19,7 @@ */ #include "port_private.h" #include "unicast_client.h" +#include "unicast_service.h" struct ptp_message *port_signaling_construct(struct port *p, struct address *address, @@ -49,7 +50,7 @@ struct ptp_message *port_signaling_construct(struct port *p, int process_signaling(struct port *p, struct ptp_message *m) { struct tlv_extra *extra; - int err = 0; + int err = 0, result; switch (p->state) { case PS_INITIALIZING: @@ -69,13 +70,29 @@ int process_signaling(struct port *p, struct ptp_message *m) TAILQ_FOREACH(extra, &m->tlv_list, list) { switch (extra->tlv->type) { case TLV_REQUEST_UNICAST_TRANSMISSION: + result = unicast_service_add(p, m, extra); + switch (result) { + case SERVICE_GRANTED: + err = unicast_service_grant(p, m, extra); + break; + case SERVICE_DENIED: + err = unicast_service_deny(p, m, extra); + break; + case SERVICE_DISABLED: + default: + break; + } break; + case TLV_GRANT_UNICAST_TRANSMISSION: unicast_client_grant(p, m, extra); break; + case TLV_CANCEL_UNICAST_TRANSMISSION: err = unicast_client_cancel(p, m, extra); + unicast_service_remove(p, m, extra); break; + case TLV_ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION: break; } diff --git a/unicast_service.c b/unicast_service.c index 8189a34..d084711 100644 --- a/unicast_service.c +++ b/unicast_service.c @@ -403,7 +403,9 @@ int unicast_service_initialize(struct port *p) if (!config_get_int(cfg, p->name, "unicast_listen")) { return 0; } - + if (config_set_section_int(cfg, p->name, "hybrid_e2e", 1)) { + return -1; + } p->unicast_service = calloc(1, sizeof(*p->unicast_service)); if (!p->unicast_service) { return -1;