Setting tag sliver-openvswitch-2.2.90-1
[sliver-openvswitch.git] / include / openvswitch / types.h
1 /*
2  * Copyright (c) 2010, 2011, 2013 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef OPENVSWITCH_TYPES_H
18 #define OPENVSWITCH_TYPES_H 1
19
20 #include <linux/types.h>
21 #include <sys/types.h>
22 #include <stdint.h>
23
24 #ifdef __CHECKER__
25 #define OVS_BITWISE __attribute__((bitwise))
26 #define OVS_FORCE __attribute__((force))
27 #else
28 #define OVS_BITWISE
29 #define OVS_FORCE
30 #endif
31
32 /* The ovs_be<N> types indicate that an object is in big-endian, not
33  * native-endian, byte order.  They are otherwise equivalent to uint<N>_t.
34  *
35  * We bootstrap these from the Linux __be<N> types.  If we instead define our
36  * own independently then __be<N> and ovs_be<N> become mutually
37  * incompatible. */
38 typedef __be16 ovs_be16;
39 typedef __be32 ovs_be32;
40 typedef __be64 ovs_be64;
41
42 #define OVS_BE16_MAX ((OVS_FORCE ovs_be16) 0xffff)
43 #define OVS_BE32_MAX ((OVS_FORCE ovs_be32) 0xffffffff)
44 #define OVS_BE64_MAX ((OVS_FORCE ovs_be64) 0xffffffffffffffffULL)
45 \f
46 /* These types help with a few funny situations:
47  *
48  *   - The Ethernet header is 14 bytes long, which misaligns everything after
49  *     that.  One can put 2 "shim" bytes before the Ethernet header, but this
50  *     helps only if there is exactly one Ethernet header.  If there are two,
51  *     as with GRE and VXLAN (and if the inner header doesn't use this
52  *     trick--GRE and VXLAN don't) then you have the choice of aligning the
53  *     inner data or the outer data.  So it seems better to treat 32-bit fields
54  *     in protocol headers as aligned only on 16-bit boundaries.
55  *
56  *   - ARP headers contain misaligned 32-bit fields.
57  *
58  *   - Netlink and OpenFlow contain 64-bit values that are only guaranteed to
59  *     be aligned on 32-bit boundaries.
60  *
61  * lib/unaligned.h has helper functions for accessing these. */
62
63 /* A 32-bit value, in host byte order, that is only aligned on a 16-bit
64  * boundary.  */
65 typedef struct {
66 #ifdef WORDS_BIGENDIAN
67         uint16_t hi, lo;
68 #else
69         uint16_t lo, hi;
70 #endif
71 } ovs_16aligned_u32;
72
73 /* A 32-bit value, in network byte order, that is only aligned on a 16-bit
74  * boundary. */
75 typedef struct {
76         ovs_be16 hi, lo;
77 } ovs_16aligned_be32;
78
79 /* A 64-bit value, in host byte order, that is only aligned on a 32-bit
80  * boundary.  */
81 typedef struct {
82 #ifdef WORDS_BIGENDIAN
83         uint32_t hi, lo;
84 #else
85         uint32_t lo, hi;
86 #endif
87 } ovs_32aligned_u64;
88
89 /* A 64-bit value, in network byte order, that is only aligned on a 32-bit
90  * boundary. */
91 typedef struct {
92         ovs_be32 hi, lo;
93 } ovs_32aligned_be64;
94
95 /* ofp_port_t represents the port number of a OpenFlow switch.
96  * odp_port_t represents the port number on the datapath.
97  * ofp11_port_t represents the OpenFlow-1.1 port number. */
98 typedef uint16_t OVS_BITWISE ofp_port_t;
99 typedef uint32_t OVS_BITWISE odp_port_t;
100 typedef uint32_t OVS_BITWISE ofp11_port_t;
101
102 /* Macro functions that cast int types to ofp/odp/ofp11 types. */
103 #define OFP_PORT_C(X) ((OVS_FORCE ofp_port_t) (X))
104 #define ODP_PORT_C(X) ((OVS_FORCE odp_port_t) (X))
105 #define OFP11_PORT_C(X) ((OVS_FORCE ofp11_port_t) (X))
106
107 #endif /* openvswitch/types.h */