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