Merge 'master' into 'next'.
[sliver-openvswitch.git] / include / openvswitch / types.h
1 /*
2  * Copyright (c) 2010, 2011 Nicira Networks.
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 <arpa/inet.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  * The OVS_BITWISE annotation allows the sparse checker to issue warnings
36  * for incorrect use of values in network byte order. */
37 typedef uint16_t OVS_BITWISE ovs_be16;
38 typedef uint32_t OVS_BITWISE ovs_be32;
39 typedef uint64_t OVS_BITWISE ovs_be64;
40 \f
41 /* Netlink and OpenFlow both contain 64-bit values that are only guaranteed to
42  * be aligned on 32-bit boundaries.  These types help.
43  *
44  * lib/unaligned.h has helper functions for accessing these. */
45
46 /* A 64-bit value, in host byte order, that is only aligned on a 32-bit
47  * boundary.  */
48 typedef struct {
49 #ifdef WORDS_BIGENDIAN
50         uint32_t hi, lo;
51 #else
52         uint32_t lo, hi;
53 #endif
54 } ovs_32aligned_u64;
55
56 /* A 64-bit value, in network byte order, that is only aligned on a 32-bit
57  * boundary. */
58 typedef struct {
59         ovs_be32 hi, lo;
60 } ovs_32aligned_be64;
61
62 #endif /* openvswitch/types.h */