dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame SOURCES/linuxptp-ucastrate.patch

63054e
commit a36602f1e65cd6bace6ed9405b0ce359de4a27d1
63054e
Author: Miroslav Lichvar <mlichvar@redhat.com>
63054e
Date:   Thu Jan 3 15:23:54 2019 +0100
63054e
63054e
    unicast: limit message rate and grant duration
63054e
    
63054e
    Deny service requests with logInterMessagePeriod smaller than -7 (128
63054e
    packets per second) or larger than 16. This limits the network and CPU
63054e
    consumption per address and prevents undefined shifts in the calculation
63054e
    of the interval.
63054e
    
63054e
    Also, limit the maximum grant duration to one hour.
63054e
    
63054e
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
63054e
63054e
diff --git a/unicast_service.c b/unicast_service.c
63054e
index 9c9b95b..c6c17c6 100644
63054e
--- a/unicast_service.c
63054e
+++ b/unicast_service.c
63054e
@@ -31,6 +31,9 @@
63054e
 #include "unicast_service.h"
63054e
 #include "util.h"
63054e
 
63054e
+#define MIN_LOG_INTER_MESSAGE_PERIOD -7
63054e
+#define MAX_LOG_INTER_MESSAGE_PERIOD 16
63054e
+#define MAX_DURATION 3600
63054e
 #define QUEUE_LEN 16
63054e
 
63054e
 struct unicast_client_address {
63054e
@@ -289,6 +292,15 @@ int unicast_service_add(struct port *p, struct ptp_message *m,
63054e
 		return SERVICE_DENIED;
63054e
 	}
63054e
 
63054e
+	if (req->logInterMessagePeriod < MIN_LOG_INTER_MESSAGE_PERIOD ||
63054e
+	    req->logInterMessagePeriod > MAX_LOG_INTER_MESSAGE_PERIOD) {
63054e
+		return SERVICE_DENIED;
63054e
+	}
63054e
+
63054e
+	if (req->durationField > MAX_DURATION) {
63054e
+		req->durationField = MAX_DURATION;
63054e
+	}
63054e
+
63054e
 	LIST_FOREACH(itmp, &p->unicast_service->intervals, list) {
63054e
 		/*
63054e
 		 * Remember the interval of interest.