Deny service requests with logInterMessagePeriod smaller than -7 (128
packets per second) or larger than 16. This limits the network and CPU
consumption per address and prevents undefined shifts in the calculation
of the interval.

Also, limit the maximum grant duration to one hour.

Signed-off-by: Miroslav Lichvar <[email protected]>
---
 unicast_service.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/unicast_service.c b/unicast_service.c
index 9c9b95b..c6c17c6 100644
--- a/unicast_service.c
+++ b/unicast_service.c
@@ -31,6 +31,9 @@
 #include "unicast_service.h"
 #include "util.h"
 
+#define MIN_LOG_INTER_MESSAGE_PERIOD -7
+#define MAX_LOG_INTER_MESSAGE_PERIOD 16
+#define MAX_DURATION 3600
 #define QUEUE_LEN 16
 
 struct unicast_client_address {
@@ -289,6 +292,15 @@ int unicast_service_add(struct port *p, struct ptp_message 
*m,
                return SERVICE_DENIED;
        }
 
+       if (req->logInterMessagePeriod < MIN_LOG_INTER_MESSAGE_PERIOD ||
+           req->logInterMessagePeriod > MAX_LOG_INTER_MESSAGE_PERIOD) {
+               return SERVICE_DENIED;
+       }
+
+       if (req->durationField > MAX_DURATION) {
+               req->durationField = MAX_DURATION;
+       }
+
        LIST_FOREACH(itmp, &p->unicast_service->intervals, list) {
                /*
                 * Remember the interval of interest.
-- 
2.17.2



_______________________________________________
Linuxptp-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to