aboutsummaryrefslogtreecommitdiffstats
path: root/utils/keytable/bpf_protocols/bitmap.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils/keytable/bpf_protocols/bitmap.h')
-rw-r--r--utils/keytable/bpf_protocols/bitmap.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/utils/keytable/bpf_protocols/bitmap.h b/utils/keytable/bpf_protocols/bitmap.h
new file mode 100644
index 00000000..e3d731ad
--- /dev/null
+++ b/utils/keytable/bpf_protocols/bitmap.h
@@ -0,0 +1,36 @@
+
+#ifndef __BITMAP_H__
+#define __BITMAP_H__
+
+#include "string.h"
+
+#define BITS_PER_LONG 64
+#define BITS_TO_LONG(n) \
+ (((n) + BITS_PER_LONG - 1) / BITS_PER_LONG)
+
+
+#define DECLARE_BITMAP(name, bits) \
+ unsigned long name[BITS_TO_LONG(bits)]
+
+static void inline bitmap_zero(unsigned long *bitmap, int bits)
+{
+ for (int i = 0; i < BITS_TO_LONG(bits); i++)
+ bitmap[i] = 0;
+}
+
+static void inline bitmap_fill(unsigned long *bitmap, int bits)
+{
+ for (int i = 0; i < BITS_TO_LONG(bits); i++)
+ bitmap[i] = ~0;
+}
+
+#define bitmap_set(b, n) \
+ b[n / BITS_PER_LONG] |= 1 << (n % BITS_PER_LONG)
+
+#define bitmap_clear(b, n) \
+ b[n / BITS_PER_LONG] &= ~(1 << (n % BITS_PER_LONG))
+
+#define bitmap_test(b, n) \
+ (b[n / BITS_PER_LONG] & (1 << (n % BITS_PER_LONG))) != 0
+
+#endif

Privacy Policy