dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame SOURCES/linuxptp-ucastrate.patch

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