datapath: Improve compat rxhash functionality.
[sliver-openvswitch.git] / datapath / linux / compat / include / linux / net.h
index 5665e2e..ae226ea 100644 (file)
@@ -2,6 +2,7 @@
 #define __LINUX_NET_WRAPPER_H 1
 
 #include_next <linux/net.h>
+#include <linux/atomic.h>
 
 #ifndef net_ratelimited_function
 #define net_ratelimited_function(function, ...)                        \
@@ -28,4 +29,26 @@ do {                                                         \
        net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
 #endif
 
+#ifndef net_get_random_once
+bool __net_get_random_once(void *buf, int nbytes, bool *done,
+                          atomic_t *done_key);
+
+#define ___NET_RANDOM_STATIC_KEY_INIT  ATOMIC_INIT(0)
+
+
+#define net_get_random_once(buf, nbytes)                       \
+({                                                             \
+       bool ___ret = false;                                    \
+       static bool ___done = false;                            \
+       static atomic_t ___done_key =                           \
+                       ___NET_RANDOM_STATIC_KEY_INIT;          \
+       if (!atomic_read(&___done_key))                         \
+               ___ret = __net_get_random_once(buf,             \
+                                              nbytes,          \
+                                              &___done,        \
+                                              &___done_key);   \
+       ___ret;                                                 \
+})
+#endif
+
 #endif