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