datapath: Use compat directory only for backported code.
[sliver-openvswitch.git] / datapath / compat.h
1 /*
2  * Copyright (c) 2011 Nicira Networks.
3  * Distributed under the terms of the GNU GPL version 2.
4  *
5  * Significant portions of this file may be copied from parts of the Linux
6  * kernel, by Linus Torvalds and others.
7  */
8
9 #ifndef COMPAT_H
10 #define COMPAT_H 1
11
12 #include <linux/netlink.h>
13
14 #ifndef HAVE_NLA_NUL_STRING
15 static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen)
16 {
17         char *s;
18         int len;
19         if (!attr)
20                 return 0;
21
22         len = nla_len(attr);
23         if (len >= maxlen)
24                 return -EINVAL;
25
26         s = nla_data(attr);
27         if (s[len - 1] != '\0')
28                 return -EINVAL;
29
30         return 0;
31 }
32 #else
33 static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen)
34 {
35         return 0;
36 }
37 #endif  /* !HAVE_NLA_NUL_STRING */
38
39 #endif /* compat.h */