dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame SOURCES/linuxptp-ucastrate.patch

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