2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-29 15:28:56 +00:00

datapath-protocol: Use Linux kernel types directly.

We want datapath-protocol.h to be acceptable as a Linux kernel header, so
it must use Linux kernel types and must not have references to Open vSwitch
symbols or header files.  This commit primarily makes that change to
datapath-protocol.h.

At the same time, at least for now we also want datapath-protocol.h to be
usable on non-Linux platforms, so we need some kind of compatiblity.  Thus,
this commit also introduces a <linux/types.h> header file that defines the
necessary Linux kernel types on non-Linux platforms.

In turn, this requires openvswitch/types.h to use the Linux types directly
for ovs_be<N>; otherwise, sparse complains because now __be<N> and
ovs_be<N> are incompatible from its perspective, so this commit makes that
change too.

I don't have a non-Linux kernel platform readily available, so I only
tested the non-Linux part of the linux/types.h substitute by forcing that
case to be triggered with #if 0.  It worked, except for errors in actual
Linux kernel headers included explicitly from OVS source files, so I think
it's likely to work in practice.

Bug #7559.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jesse Gross <jesse@nicira.com>
This commit is contained in:
Ben Pfaff
2011-10-05 10:42:34 -07:00
parent 09ded0ad48
commit 9ea0bccc83
7 changed files with 103 additions and 58 deletions

View File

@@ -56,7 +56,7 @@ OVS_CHECK_STRTOK_R
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec], AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec],
[], [], [[#include <sys/stat.h>]]) [], [], [[#include <sys/stat.h>]])
AC_CHECK_FUNCS([mlockall strnlen strsignal getloadavg statvfs setmntent]) AC_CHECK_FUNCS([mlockall strnlen strsignal getloadavg statvfs setmntent])
AC_CHECK_HEADERS([mntent.h sys/statvfs.h]) AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h])
OVS_CHECK_PKIDIR OVS_CHECK_PKIDIR
OVS_CHECK_RUNDIR OVS_CHECK_RUNDIR

View File

@@ -1,3 +1,4 @@
include include/linux/automake.mk
include include/openflow/automake.mk include include/openflow/automake.mk
include include/openvswitch/automake.mk include include/openvswitch/automake.mk
include include/sparse/automake.mk include include/sparse/automake.mk

View File

@@ -0,0 +1 @@
noinst_HEADERS += include/linux/types.h

47
include/linux/types.h Normal file
View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2011 Nicira Networks.
*
* 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 datapath-protocol.h to work, that is, it defines
* the __u<N> and __be<N> types. */
#if __KERNEL__ || HAVE_LINUX_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> */

View File

@@ -40,15 +40,8 @@
#ifndef OPENVSWITCH_DATAPATH_PROTOCOL_H #ifndef OPENVSWITCH_DATAPATH_PROTOCOL_H
#define OPENVSWITCH_DATAPATH_PROTOCOL_H 1 #define OPENVSWITCH_DATAPATH_PROTOCOL_H 1
#ifdef __KERNEL__
#include <linux/types.h> #include <linux/types.h>
#define ovs_be16 __be16
#define ovs_be32 __be32
#define ovs_be64 __be64
#else
#include "openvswitch/types.h"
#endif
/* datapaths. */ /* datapaths. */
#define OVS_DATAPATH_FAMILY "ovs_datapath" #define OVS_DATAPATH_FAMILY "ovs_datapath"
@@ -119,26 +112,26 @@ enum ovs_datapath_frag {
}; };
struct ovs_dp_stats { struct ovs_dp_stats {
uint64_t n_frags; /* Number of dropped IP fragments. */ __u64 n_frags; /* Number of dropped IP fragments. */
uint64_t n_hit; /* Number of flow table matches. */ __u64 n_hit; /* Number of flow table matches. */
uint64_t n_missed; /* Number of flow table misses. */ __u64 n_missed; /* Number of flow table misses. */
uint64_t n_lost; /* Number of misses not sent to userspace. */ __u64 n_lost; /* Number of misses not sent to userspace. */
uint64_t n_flows; /* Number of flows present */ __u64 n_flows; /* Number of flows present */
}; };
struct ovs_vport_stats { struct ovs_vport_stats {
uint64_t rx_packets; /* total packets received */ __u64 rx_packets; /* total packets received */
uint64_t tx_packets; /* total packets transmitted */ __u64 tx_packets; /* total packets transmitted */
uint64_t rx_bytes; /* total bytes received */ __u64 rx_bytes; /* total bytes received */
uint64_t tx_bytes; /* total bytes transmitted */ __u64 tx_bytes; /* total bytes transmitted */
uint64_t rx_errors; /* bad packets received */ __u64 rx_errors; /* bad packets received */
uint64_t tx_errors; /* packet transmit problems */ __u64 tx_errors; /* packet transmit problems */
uint64_t rx_dropped; /* no space in linux buffers */ __u64 rx_dropped; /* no space in linux buffers */
uint64_t tx_dropped; /* no space available in linux */ __u64 tx_dropped; /* no space available in linux */
}; };
/* Logical ports. */ /* Logical ports. */
#define OVSP_LOCAL ((uint16_t)0) #define OVSP_LOCAL ((__u16)0)
#define OVS_PACKET_FAMILY "ovs_packet" #define OVS_PACKET_FAMILY "ovs_packet"
@@ -273,8 +266,8 @@ enum ovs_flow_cmd {
}; };
struct ovs_flow_stats { struct ovs_flow_stats {
uint64_t n_packets; /* Number of matched packets. */ __u64 n_packets; /* Number of matched packets. */
uint64_t n_bytes; /* Number of matched bytes. */ __u64 n_bytes; /* Number of matched bytes. */
}; };
enum ovs_key_attr { enum ovs_key_attr {
@@ -298,61 +291,61 @@ enum ovs_key_attr {
#define OVS_KEY_ATTR_MAX (__OVS_KEY_ATTR_MAX - 1) #define OVS_KEY_ATTR_MAX (__OVS_KEY_ATTR_MAX - 1)
struct ovs_key_ethernet { struct ovs_key_ethernet {
uint8_t eth_src[6]; __u8 eth_src[6];
uint8_t eth_dst[6]; __u8 eth_dst[6];
}; };
struct ovs_key_8021q { struct ovs_key_8021q {
ovs_be16 q_tpid; __be16 q_tpid;
ovs_be16 q_tci; __be16 q_tci;
}; };
struct ovs_key_ipv4 { struct ovs_key_ipv4 {
ovs_be32 ipv4_src; __be32 ipv4_src;
ovs_be32 ipv4_dst; __be32 ipv4_dst;
uint8_t ipv4_proto; __u8 ipv4_proto;
uint8_t ipv4_tos; __u8 ipv4_tos;
}; };
struct ovs_key_ipv6 { struct ovs_key_ipv6 {
ovs_be32 ipv6_src[4]; __be32 ipv6_src[4];
ovs_be32 ipv6_dst[4]; __be32 ipv6_dst[4];
uint8_t ipv6_proto; __u8 ipv6_proto;
uint8_t ipv6_tos; __u8 ipv6_tos;
}; };
struct ovs_key_tcp { struct ovs_key_tcp {
ovs_be16 tcp_src; __be16 tcp_src;
ovs_be16 tcp_dst; __be16 tcp_dst;
}; };
struct ovs_key_udp { struct ovs_key_udp {
ovs_be16 udp_src; __be16 udp_src;
ovs_be16 udp_dst; __be16 udp_dst;
}; };
struct ovs_key_icmp { struct ovs_key_icmp {
uint8_t icmp_type; __u8 icmp_type;
uint8_t icmp_code; __u8 icmp_code;
}; };
struct ovs_key_icmpv6 { struct ovs_key_icmpv6 {
uint8_t icmpv6_type; __u8 icmpv6_type;
uint8_t icmpv6_code; __u8 icmpv6_code;
}; };
struct ovs_key_arp { struct ovs_key_arp {
ovs_be32 arp_sip; __be32 arp_sip;
ovs_be32 arp_tip; __be32 arp_tip;
ovs_be16 arp_op; __be16 arp_op;
uint8_t arp_sha[6]; __u8 arp_sha[6];
uint8_t arp_tha[6]; __u8 arp_tha[6];
}; };
struct ovs_key_nd { struct ovs_key_nd {
uint32_t nd_target[4]; __u32 nd_target[4];
uint8_t nd_sll[6]; __u8 nd_sll[6];
uint8_t nd_tll[6]; __u8 nd_tll[6];
}; };
/** /**

View File

@@ -17,6 +17,7 @@
#ifndef OPENVSWITCH_TYPES_H #ifndef OPENVSWITCH_TYPES_H
#define OPENVSWITCH_TYPES_H 1 #define OPENVSWITCH_TYPES_H 1
#include <linux/types.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h> #include <stdint.h>
@@ -31,11 +32,12 @@
/* The ovs_be<N> types indicate that an object is in big-endian, not /* 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. * native-endian, byte order. They are otherwise equivalent to uint<N>_t.
* *
* The OVS_BITWISE annotation allows the sparse checker to issue warnings * We bootstrap these from the Linux __be<N> types. If we instead define our
* for incorrect use of values in network byte order. */ * own independently then __be<N> and ovs_be<N> become mutually
typedef uint16_t OVS_BITWISE ovs_be16; * incompatible. */
typedef uint32_t OVS_BITWISE ovs_be32; typedef __be16 ovs_be16;
typedef uint64_t OVS_BITWISE ovs_be64; typedef __be32 ovs_be32;
typedef __be64 ovs_be64;
/* Netlink and OpenFlow both contain 64-bit values that are only guaranteed to /* Netlink and OpenFlow both contain 64-bit values that are only guaranteed to
* be aligned on 32-bit boundaries. These types help. * be aligned on 32-bit boundaries. These types help.

View File

@@ -18,6 +18,7 @@
#define DPIF_LINUX_H 1 #define DPIF_LINUX_H 1
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "openvswitch/datapath-protocol.h" #include "openvswitch/datapath-protocol.h"