]> git.bitcoin.ninja Git - flowspec-xdp/commitdiff
Remove extra shift in per_pkt_ns for readability
authorMatt Corallo <git@bluematt.me>
Sun, 16 Jun 2024 00:52:58 +0000 (00:52 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 16 Jun 2024 00:52:58 +0000 (00:52 +0000)
Having a shift in one place and unshift in a totally different file
is confusing.

genrules.py
xdp.c

index a9f3d16db50c54ee04830757a4d5482fd8d7f39c..69fa58855ed31318570a88364e02e6da025aa293 100755 (executable)
@@ -543,7 +543,7 @@ with open("rules.h", "w") as out:
                         value *= 2**(exp-127)
 
                         first_action =   "int64_t time_masked = bpf_ktime_get_ns() & RATE_TIME_MASK;\n"
-                        first_action += f"int64_t per_pkt_ns = (1000000000LL << RATE_BUCKET_INTEGER_BITS) / {math.floor(value)};\n"
+                        first_action += f"int64_t per_pkt_ns = 1000000000LL / {math.floor(value)};\n"
                         if ty == "0x8006" or ty == "0x8306":
                             first_action += "uint64_t amt = data_end - pktdata;\n"
                         else:
diff --git a/xdp.c b/xdp.c
index 860fe2536bc3723f19272a0e72e0ada00161deda..d5bd0b05ccd40b5331ebfcd7566cb3075cec3d39 100644 (file)
--- a/xdp.c
+++ b/xdp.c
@@ -249,7 +249,7 @@ if (rate) { \
                /* time difference / (our ns/packet limit * the size of the current packet). */ \
                /* We shift by RATE_BUCKET_DECIMAL_BITS first since we're calculating whole packets. */ \
                int64_t pkts_allowed_since_last_update = \
-                       (time_diff << RATE_BUCKET_BITS) / (((uint64_t)amt_in_pkt) * ((uint64_t)limit_ns_per_pkt)); \
+                       (time_diff << RATE_BUCKET_DECIMAL_BITS) / (((uint64_t)amt_in_pkt) * ((uint64_t)limit_ns_per_pkt)); \
                bucket_pkts -= pkts_allowed_since_last_update; \
        } \
        /* Accept as long as we can add one to our bucket without overflow */ \