From: Jesse Gross Date: Fri, 11 Mar 2011 22:58:18 +0000 (-0800) Subject: datapath: Use compat directory only for backported code. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cb8d24da006b562fecd17d34971822e3f6d1a78;p=openvswitch datapath: Use compat directory only for backported code. Most necessary compatibility code is simply backported versions of kernel functions from newer kernels. These belong in the compat directory, where they can be transparently picked up when necessary. However, in some situations there is code that is different depending on the kernel version but is always needed in some form. Here it is desirable to segregate the code but it does not really belong in the compat directory because it does not exist in upstream kernels. This moves those functions to a compat file, which makes the meaning clear and prevents problems when Open vSwitch is integrated into other projects. Signed-off-by: Jesse Gross Acked-by: Ben Pfaff --- diff --git a/datapath/Modules.mk b/datapath/Modules.mk index dbeec8fb..587569f2 100644 --- a/datapath/Modules.mk +++ b/datapath/Modules.mk @@ -32,6 +32,7 @@ openvswitch_sources = \ openvswitch_headers = \ actions.h \ checksum.h \ + compat.h \ datapath.h \ dp_sysfs.h \ flow.h \ diff --git a/datapath/compat.h b/datapath/compat.h new file mode 100644 index 00000000..c484a5d7 --- /dev/null +++ b/datapath/compat.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011 Nicira Networks. + * Distributed under the terms of the GNU GPL version 2. + * + * Significant portions of this file may be copied from parts of the Linux + * kernel, by Linus Torvalds and others. + */ + +#ifndef COMPAT_H +#define COMPAT_H 1 + +#include + +#ifndef HAVE_NLA_NUL_STRING +static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen) +{ + char *s; + int len; + if (!attr) + return 0; + + len = nla_len(attr); + if (len >= maxlen) + return -EINVAL; + + s = nla_data(attr); + if (s[len - 1] != '\0') + return -EINVAL; + + return 0; +} +#else +static inline int CHECK_NUL_STRING(struct nlattr *attr, int maxlen) +{ + return 0; +} +#endif /* !HAVE_NLA_NUL_STRING */ + +#endif /* compat.h */ diff --git a/datapath/datapath.c b/datapath/datapath.c index b25b8996..8a550012 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -1304,7 +1304,7 @@ static int odp_dp_cmd_validate(struct nlattr *a[ODP_DP_ATTR_MAX + 1]) return -EINVAL; } - return VERIFY_NUL_STRING(a[ODP_DP_ATTR_NAME], IFNAMSIZ - 1); + return CHECK_NUL_STRING(a[ODP_DP_ATTR_NAME], IFNAMSIZ - 1); } /* Called with genl_mutex and optionally with RTNL lock also. */ @@ -1674,7 +1674,7 @@ static struct sk_buff *odp_vport_cmd_build_info(struct vport *vport, u32 pid, static int odp_vport_cmd_validate(struct nlattr *a[ODP_VPORT_ATTR_MAX + 1]) { - return VERIFY_NUL_STRING(a[ODP_VPORT_ATTR_NAME], IFNAMSIZ - 1); + return CHECK_NUL_STRING(a[ODP_VPORT_ATTR_NAME], IFNAMSIZ - 1); } /* Called with RTNL lock or RCU read lock. */ diff --git a/datapath/datapath.h b/datapath/datapath.h index a7795105..a0649064 100644 --- a/datapath/datapath.h +++ b/datapath/datapath.h @@ -20,6 +20,7 @@ #include #include "checksum.h" +#include "compat.h" #include "flow.h" #include "dp_sysfs.h" #include "vlan.h" diff --git a/datapath/linux-2.6/compat-2.6/include/net/netlink.h b/datapath/linux-2.6/compat-2.6/include/net/netlink.h index aa7c09c0..10558b07 100644 --- a/datapath/linux-2.6/compat-2.6/include/net/netlink.h +++ b/datapath/linux-2.6/compat-2.6/include/net/netlink.h @@ -29,31 +29,6 @@ #define NLA_NESTED NLA_UNSPEC #endif -#ifndef HAVE_NLA_NUL_STRING -static inline int VERIFY_NUL_STRING(struct nlattr *attr, int maxlen) -{ - char *s; - int len; - if (!attr) - return 0; - - len = nla_len(attr); - if (len >= maxlen) - return -EINVAL; - - s = nla_data(attr); - if (s[len - 1] != '\0') - return -EINVAL; - - return 0; -} -#else -static inline int VERIFY_NUL_STRING(struct nlattr *attr, int maxlen) -{ - return 0; -} -#endif /* !HAVE_NLA_NUL_STRING */ - #ifndef NLA_PUT_BE16 #define NLA_PUT_BE16(skb, attrtype, value) \ NLA_PUT_TYPE(skb, __be16, attrtype, value) diff --git a/datapath/vport-patch.c b/datapath/vport-patch.c index 1c4d2c5e..7cb221e4 100644 --- a/datapath/vport-patch.c +++ b/datapath/vport-patch.c @@ -11,6 +11,7 @@ #include #include +#include "compat.h" #include "datapath.h" #include "vport.h" #include "vport-generic.h" @@ -105,7 +106,8 @@ static int patch_set_config(struct vport *vport, const struct nlattr *options, if (err) return err; - if (!a[ODP_PATCH_ATTR_PEER] || VERIFY_NUL_STRING(a[ODP_PATCH_ATTR_PEER], IFNAMSIZ - 1)) + if (!a[ODP_PATCH_ATTR_PEER] || + CHECK_NUL_STRING(a[ODP_PATCH_ATTR_PEER], IFNAMSIZ - 1)) return -EINVAL; peer_name = nla_data(a[ODP_PATCH_ATTR_PEER]);