[ovs-dev] [PATCH v2 1/2] Do not seemingly #include Linux-specific headers on other platforms.

Ben Pfaff blp at nicira.com
Sat Aug 2 04:36:52 UTC 2014


Until now, the OVS source tree has had a whole maze of header files that
make "#include <linux/openvswitch.h>" work OK regardless of platform, but
this confuses everyone new to the tree, at first glance, and is difficult
to understand at second glance too.

This commit renames include/linux/openvswitch.h to
datapath/linux/compat/include/linux/openvswitch.h without other change,
then modifies the userspace build to generate a header that makes sense in
portable Open vSwitch userspace from that header.

It then removes all the remaining include/linux/* files since they are now
unused.

Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 Makefile.am                                        |  1 +
 build-aux/extract-odp-netlink-h                    | 28 +++++++++++
 datapath/linux/Modules.mk                          |  1 +
 .../linux/compat/include}/linux/openvswitch.h      |  0
 debian/copyright.in                                |  2 +-
 include/automake.mk                                |  9 +++-
 include/linux/automake.mk                          |  4 --
 include/linux/if_ether.h                           | 31 ------------
 include/linux/types.h                              | 58 ----------------------
 include/openvswitch/types.h                        | 15 ++----
 lib/dpif-linux.h                                   |  4 +-
 lib/dpif.h                                         |  7 ++-
 lib/odp-execute.c                                  |  2 +-
 lib/odp-util.h                                     |  2 +-
 14 files changed, 51 insertions(+), 113 deletions(-)
 create mode 100755 build-aux/extract-odp-netlink-h
 rename {include => datapath/linux/compat/include}/linux/openvswitch.h (100%)
 delete mode 100644 include/linux/automake.mk
 delete mode 100644 include/linux/if_ether.h
 delete mode 100644 include/linux/types.h

diff --git a/Makefile.am b/Makefile.am
index f62198b..eddacaf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -20,6 +20,7 @@ AM_LDFLAGS += $(PTHREAD_LDFLAGS)
 endif
 
 AM_CPPFLAGS += -I $(top_srcdir)/include
+AM_CPPFLAGS += -I $(top_builddir)/include
 AM_CPPFLAGS += -I $(top_srcdir)/lib
 AM_CPPFLAGS += -I $(top_builddir)/lib
 
diff --git a/build-aux/extract-odp-netlink-h b/build-aux/extract-odp-netlink-h
new file mode 100755
index 0000000..f3441c1
--- /dev/null
+++ b/build-aux/extract-odp-netlink-h
@@ -0,0 +1,28 @@
+# This is a "sed" script that transforms <linux/openvswitch.h> into a
+# form that is suitable for inclusion within the Open vSwitch tree on
+# both Linux and non-Linux systems.
+
+# Add a header warning that this is a generated file.  It might save somebody
+# some frustration (maybe even me!).
+1i\
+/* -*- mode: c; buffer-read-only: t -*- */\
+/* Generated automatically from <linux/openvswitch.h> -- do not modify! */
+
+# Avoid using reserved names in header guards.
+s/_LINUX_OPENVSWITCH_H/ODP_NETLINK_H/
+
+# Transform Linux-specific __u<N> types into C99 uint<N>_t types,
+# and Linux-specific __be<N> into Open vSwitch ovs_be<N>,
+# and use the appropriate userspace header.
+s,<linux/types\.h>,"openvswitch/types.h",
+s/__u64/uint64_t/g
+s/__u32/uint32_t/g
+s/__u16/uint16_t/g
+s/__u8/uint8_t/g
+s/__be64/ovs_be64/g
+s/__be32/ovs_be32/g
+s/__be16/ovs_be16/g
+
+# Use OVS's own ETH_ADDR_LEN instead of Linux-specific ETH_ALEN.
+s,<linux/if_ether\.h>,"packets.h",
+s/ETH_ALEN/ETH_ADDR_LEN/
diff --git a/datapath/linux/Modules.mk b/datapath/linux/Modules.mk
index 46aa1f6..0b9fffa 100644
--- a/datapath/linux/Modules.mk
+++ b/datapath/linux/Modules.mk
@@ -46,6 +46,7 @@ openvswitch_headers += \
 	linux/compat/include/linux/netdevice.h \
 	linux/compat/include/linux/netdev_features.h \
 	linux/compat/include/linux/netlink.h \
+	linux/compat/include/linux/openvswitch.h \
 	linux/compat/include/linux/poison.h \
 	linux/compat/include/linux/rculist.h \
 	linux/compat/include/linux/rcupdate.h \
diff --git a/include/linux/openvswitch.h b/datapath/linux/compat/include/linux/openvswitch.h
similarity index 100%
rename from include/linux/openvswitch.h
rename to datapath/linux/compat/include/linux/openvswitch.h
diff --git a/debian/copyright.in b/debian/copyright.in
index 89cd2d2..811a378 100644
--- a/debian/copyright.in
+++ b/debian/copyright.in
@@ -95,7 +95,7 @@ License:
 * The following components are dual-licensed under the
   GNU General Public License version 2 and the Apache License Version 2.0.
 
-	include/linux/openvswitch.h
+	datapath/linux/compat/include/linux/openvswitch.h
 
   On Debian systems, the complete text of the GNU General Public License
   version 2 can be found in `/usr/share/common-licenses/GPL-2'.
diff --git a/include/automake.mk b/include/automake.mk
index 37a6f77..55cb353 100644
--- a/include/automake.mk
+++ b/include/automake.mk
@@ -1,4 +1,11 @@
-include include/linux/automake.mk
+BUILT_SOURCES += include/odp-netlink.h
+
+include/odp-netlink.h: datapath/linux/compat/include/linux/openvswitch.h \
+                       build-aux/extract-odp-netlink-h
+	sed -f $(srcdir)/build-aux/extract-odp-netlink-h < $< > $@
+EXTRA_DIST += build-aux/extract-odp-netlink-h
+CLEANFILES += include/odp-netlink.h
+
 include include/openflow/automake.mk
 include include/openvswitch/automake.mk
 include include/sparse/automake.mk
diff --git a/include/linux/automake.mk b/include/linux/automake.mk
deleted file mode 100644
index 6ca0e40..0000000
--- a/include/linux/automake.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-noinst_HEADERS += \
-	include/linux/if_ether.h \
-	include/linux/openvswitch.h \
-	include/linux/types.h
diff --git a/include/linux/if_ether.h b/include/linux/if_ether.h
deleted file mode 100644
index a3cc9bc..0000000
--- a/include/linux/if_ether.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2013 Nicira, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef LINUX_IF_ETHER_H
-#define LINUX_IF_ETHER_H 1
-
-/* On Linux, this header file just includes <linux/if_ether.h>.
- *
- * On other platforms, this header file implements just enough of
- * <linux/if_ether.h> to allow <linux/openvswitch.h> to work. */
-
-#if defined(HAVE_LINUX_IF_ETHER_H) || defined(__KERNEL__)
-#include_next <linux/if_ether.h>
-#else  /* no <linux/if_ether.h> */
-#define ETH_ALEN        6               /* Octets in one ethernet addr   */
-#endif
-
-#endif /* <linux/if_ether.h> */
diff --git a/include/linux/types.h b/include/linux/types.h
deleted file mode 100644
index 5438a43..0000000
--- a/include/linux/types.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 2011, 2014 Nicira, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef LINUX_TYPES_H
-#define LINUX_TYPES_H 1
-
-/* On Linux, this header file just includes <linux/types.h>.
- *
- * On other platforms, this header file implements just enough of
- * <linux/types.h> to allow <linux/openvswitch.h> to work, that is, it defines
- * the __u<N> and __be<N> types. */
-
-#ifdef __KERNEL__
-#include_next <linux/types.h>
-#elif defined(HAVE_LINUX_TYPES_H)
-/* With some combinations of kernel and userspace headers, including both
- * <sys/types.h> and <linux/types.h> only works if you do so in that order, so
- * force it.  */
-
-#ifdef __CHECKER__
-#define __CHECK_ENDIAN__
-#endif
-
-#include <sys/types.h>
-#include_next <linux/types.h>
-#else  /* no <linux/types.h> */
-#include <stdint.h>
-
-#ifdef __CHECKER__
-#define __bitwise__ __attribute__((bitwise))
-#else
-#define __bitwise__
-#endif
-
-typedef uint8_t  __u8;
-typedef uint16_t __u16;
-typedef uint32_t __u32;
-typedef uint64_t __u64;
-
-typedef uint16_t __bitwise__ __be16;
-typedef uint32_t __bitwise__ __be32;
-typedef uint64_t __bitwise__ __be64;
-#endif	/* no <linux/types.h> */
-
-#endif /* <linux/types.h> */
diff --git a/include/openvswitch/types.h b/include/openvswitch/types.h
index d9a5dc8..54541a4 100644
--- a/include/openvswitch/types.h
+++ b/include/openvswitch/types.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2011, 2013 Nicira, Inc.
+ * Copyright (c) 2010, 2011, 2013, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
 #ifndef OPENVSWITCH_TYPES_H
 #define OPENVSWITCH_TYPES_H 1
 
-#include <linux/types.h>
 #include <sys/types.h>
 #include <stdint.h>
 
@@ -30,14 +29,10 @@
 #endif
 
 /* The ovs_be<N> types indicate that an object is in big-endian, not
- * native-endian, byte order.  They are otherwise equivalent to uint<N>_t.
- *
- * We bootstrap these from the Linux __be<N> types.  If we instead define our
- * own independently then __be<N> and ovs_be<N> become mutually
- * incompatible. */
-typedef __be16 ovs_be16;
-typedef __be32 ovs_be32;
-typedef __be64 ovs_be64;
+ * native-endian, byte order.  They are otherwise equivalent to uint<N>_t. */
+typedef uint16_t OVS_BITWISE ovs_be16;
+typedef uint32_t OVS_BITWISE ovs_be32;
+typedef uint64_t OVS_BITWISE ovs_be64;
 
 #define OVS_BE16_MAX ((OVS_FORCE ovs_be16) 0xffff)
 #define OVS_BE32_MAX ((OVS_FORCE ovs_be32) 0xffffffff)
diff --git a/lib/dpif-linux.h b/lib/dpif-linux.h
index 21d0048..a35826c 100644
--- a/lib/dpif-linux.h
+++ b/lib/dpif-linux.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2011 Nicira, Inc.
+ * Copyright (c) 2010, 2011, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
-#include <linux/openvswitch.h>
+#include "odp-netlink.h"
 
 #include "flow.h"
 
diff --git a/lib/dpif.h b/lib/dpif.h
index 8d8e43a..f4a2a9e 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -115,7 +115,7 @@
  *      a flow, but the datapath interface uses a different data format to
  *      allow ABI forward- and backward-compatibility.  datapath/README
  *      describes the rationale and design.  Refer to OVS_KEY_ATTR_* and
- *      "struct ovs_key_*" in include/linux/openvswitch.h for details.
+ *      "struct ovs_key_*" in include/odp-netlink.h for details.
  *      lib/odp-util.h defines several functions for working with these flows.
  *
  *    - A "mask" that, for each bit in the flow, specifies whether the datapath
@@ -154,9 +154,8 @@
  *      within a flow.  Some examples of actions are OVS_ACTION_ATTR_OUTPUT,
  *      which transmits the packet out a port, and OVS_ACTION_ATTR_SET, which
  *      modifies packet headers.  Refer to OVS_ACTION_ATTR_* and "struct
- *      ovs_action_*" in include/linux/openvswitch.h for details.
- *      lib/odp-util.h defines several functions for working with datapath
- *      actions.
+ *      ovs_action_*" in include/odp-netlink.h for details.  lib/odp-util.h
+ *      defines several functions for working with datapath actions.
  *
  *      The actions list may be empty.  This indicates that nothing should be
  *      done to matching packets, that is, they should be dropped.
diff --git a/lib/odp-execute.c b/lib/odp-execute.c
index cb89e72..e1e9b57 100644
--- a/lib/odp-execute.c
+++ b/lib/odp-execute.c
@@ -17,13 +17,13 @@
 
 #include <config.h>
 #include "odp-execute.h"
-#include <linux/openvswitch.h>
 #include <stdlib.h>
 #include <string.h>
 
 #include "dpif.h"
 #include "netlink.h"
 #include "ofpbuf.h"
+#include "odp-netlink.h"
 #include "odp-util.h"
 #include "packet-dpif.h"
 #include "packets.h"
diff --git a/lib/odp-util.h b/lib/odp-util.h
index 4ce693c..82ab06d 100644
--- a/lib/odp-util.h
+++ b/lib/odp-util.h
@@ -21,10 +21,10 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <string.h>
-#include <linux/openvswitch.h>
 #include "flow.h"
 #include "hash.h"
 #include "hmap.h"
+#include "odp-netlink.h"
 #include "openflow/openflow.h"
 #include "util.h"
 
-- 
1.9.1




More information about the dev mailing list