Support ratelimiting communities
[flowspec-xdp] / xdp.c
diff --git a/xdp.c b/xdp.c
index 3ebec88555e37bb82ac5ca6868e8ef0e0c5d20d5..d9aa0766f75efdec39aecb191c4a176d2ce1d862 100644 (file)
--- a/xdp.c
+++ b/xdp.c
@@ -162,6 +162,20 @@ struct bpf_map_def SEC("maps") drop_cnt_map = {
                *value += 1; \
 }
 
+#ifdef RATE_CNT
+struct ratelimit {
+       struct bpf_spin_lock lock;
+       uint64_t bucket_secs;
+       uint64_t bucket_count;
+};
+struct {
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, RATE_CNT);
+       __u32 *key;
+       struct ratelimit *value;
+} rate_map SEC(".maps");
+#endif
+
 SEC("xdp_drop")
 #endif
 int xdp_drop_prog(struct xdp_md *ctx)