From 837eefc76b3c79bb790a4c4c2d0a314d81b71a28 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 4 Aug 2014 11:11:40 -0700 Subject: [PATCH] Do not seemingly #include Linux-specific headers on other platforms. Until now, the OVS source tree has had a whole maze of header files that make "#include " 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 Acked-by: Jesse Gross --- Makefile.am | 1 + build-aux/extract-odp-netlink-h | 31 ++++++++++ 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, 54 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 f62198bca..eddacafd4 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 000000000..c61a1b73a --- /dev/null +++ b/build-aux/extract-odp-netlink-h @@ -0,0 +1,31 @@ +# This is a "sed" script that transforms 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 -- do not modify! */\ +\ +\ + + +# Avoid using reserved names in header guards. +s/_LINUX_OPENVSWITCH_H/ODP_NETLINK_H/ + +# Transform Linux-specific __u types into C99 uint_t types, +# and Linux-specific __be into Open vSwitch ovs_be, +# and use the appropriate userspace header. +s,,"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,,"packets.h", +s/ETH_ALEN/ETH_ADDR_LEN/ diff --git a/datapath/linux/Modules.mk b/datapath/linux/Modules.mk index 46aa1f675..0b9fffa6f 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 89cd2d216..811a378f3 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 37a6f77af..55cb353ac 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 6ca0e4017..000000000 --- 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 a3cc9bc44..000000000 --- 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 . - * - * On other platforms, this header file implements just enough of - * to allow to work. */ - -#if defined(HAVE_LINUX_IF_ETHER_H) || defined(__KERNEL__) -#include_next -#else /* no */ -#define ETH_ALEN 6 /* Octets in one ethernet addr */ -#endif - -#endif /* */ diff --git a/include/linux/types.h b/include/linux/types.h deleted file mode 100644 index 5438a430d..000000000 --- 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 . - * - * On other platforms, this header file implements just enough of - * to allow to work, that is, it defines - * the __u and __be types. */ - -#ifdef __KERNEL__ -#include_next -#elif defined(HAVE_LINUX_TYPES_H) -/* With some combinations of kernel and userspace headers, including both - * and only works if you do so in that order, so - * force it. */ - -#ifdef __CHECKER__ -#define __CHECK_ENDIAN__ -#endif - -#include -#include_next -#else /* no */ -#include - -#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 */ - -#endif /* */ diff --git a/include/openvswitch/types.h b/include/openvswitch/types.h index d9a5dc883..54541a42b 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 #include #include @@ -30,14 +29,10 @@ #endif /* The ovs_be types indicate that an object is in big-endian, not - * native-endian, byte order. They are otherwise equivalent to uint_t. - * - * We bootstrap these from the Linux __be types. If we instead define our - * own independently then __be and ovs_be 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_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 21d00484f..a35826c8e 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 #include #include -#include +#include "odp-netlink.h" #include "flow.h" diff --git a/lib/dpif.h b/lib/dpif.h index 8d8e43a26..f4a2a9e87 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 cb89e72fa..e1e9b5718 100644 --- a/lib/odp-execute.c +++ b/lib/odp-execute.c @@ -17,13 +17,13 @@ #include #include "odp-execute.h" -#include #include #include #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 4ce693c7e..82ab06d22 100644 --- a/lib/odp-util.h +++ b/lib/odp-util.h @@ -21,10 +21,10 @@ #include #include #include -#include #include "flow.h" #include "hash.h" #include "hmap.h" +#include "odp-netlink.h" #include "openflow/openflow.h" #include "util.h" -- 2.20.1