dcavalca / rpms / linuxptp

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