Skip to content

Commit

Permalink
Do not seemingly #include Linux-specific headers on other platforms.
Browse files Browse the repository at this point in the history
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@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
  • Loading branch information
blp committed Aug 4, 2014
1 parent fa6395d commit 837eefc
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 113 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -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

Expand Down
31 changes: 31 additions & 0 deletions build-aux/extract-odp-netlink-h
@@ -0,0 +1,31 @@
# 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/
1 change: 1 addition & 0 deletions datapath/linux/Modules.mk
Expand Up @@ -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 \
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion debian/copyright.in
Expand Up @@ -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'.
Expand Down
9 changes: 8 additions & 1 deletion 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
Expand Down
4 changes: 0 additions & 4 deletions include/linux/automake.mk

This file was deleted.

31 changes: 0 additions & 31 deletions include/linux/if_ether.h

This file was deleted.

58 changes: 0 additions & 58 deletions include/linux/types.h

This file was deleted.

15 changes: 5 additions & 10 deletions 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.
Expand All @@ -17,7 +17,6 @@
#ifndef OPENVSWITCH_TYPES_H
#define OPENVSWITCH_TYPES_H 1

#include <linux/types.h>
#include <sys/types.h>
#include <stdint.h>

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions 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.
Expand All @@ -20,7 +20,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <linux/openvswitch.h>
#include "odp-netlink.h"

#include "flow.h"

Expand Down
7 changes: 3 additions & 4 deletions lib/dpif.h
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/odp-execute.c
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/odp-util.h
Expand Up @@ -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"

Expand Down

0 comments on commit 837eefc

Please sign in to comment.