datapath: Add support for kernels 3.13
[sliver-openvswitch.git] / datapath / linux / compat / utils.c
index 844d372..9404e20 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/mm.h>
 #include <linux/net.h>
 #include <net/checksum.h>
+#include <net/ip.h>
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/percpu.h>
@@ -37,3 +38,26 @@ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
                                        csum_unfold(*sum)));
 }
 #endif
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
+bool __net_get_random_once(void *buf, int nbytes, bool *done,
+                          atomic_t *done_key)
+{
+       static DEFINE_SPINLOCK(lock);
+       unsigned long flags;
+
+       spin_lock_irqsave(&lock, flags);
+       if (*done) {
+               spin_unlock_irqrestore(&lock, flags);
+               return false;
+       }
+
+       get_random_bytes(buf, nbytes);
+       *done = true;
+       spin_unlock_irqrestore(&lock, flags);
+
+       atomic_set(done_key, 1);
+
+       return true;
+}
+#endif