summaryrefslogtreecommitdiff
path: root/datapath-windows/ovsext/Netlink/NetlinkProto.h
blob: 898cc84f16e72fb5108ca32c6322d21f377c94f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (c) 2008, 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.
 * 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 __NETLINK_PROTO_H_
#define __NETLINK_PROTO_H_ 1

/* Netlink protocol definitions.
 *
 * Netlink is a message framing format described in RFC 3549 and used heavily
 * in Linux to access the network stack.  Open vSwitch uses AF_NETLINK sockets
 * for this purpose on Linux.  On Windows platform too, Open vSwitch uses
 * netlink message format for userspace-kernelspace communication.
 *
 * This header provides access to the Netlink message framing definitions
 * regardless of platform.
 */
#include "Types.h"

#define BUILD_ASSERT(EXPR) \
        typedef char AssertOnCompileFailed[(EXPR) ? 1: -1]
#define BUILD_ASSERT_DECL(EXPR) BUILD_ASSERT(EXPR)

/* Returns X / Y, rounding up.  X must be nonnegative to round correctly. */
#define DIV_ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y))

/* Returns X rounded up to the nearest multiple of Y. */
#define ROUND_UP(X, Y) (DIV_ROUND_UP(X, Y) * (Y))

/* Netlink message */

/* nlmsg_flags bits. */
#define NLM_F_REQUEST           0x001
#define NLM_F_MULTI             0x002
#define NLM_F_ACK               0x004
#define NLM_F_ECHO              0x008

#define NLM_F_ROOT              0x100
#define NLM_F_MATCH             0x200
#define NLM_F_EXCL              0x200
#define NLM_F_ATOMIC            0x400
#define NLM_F_CREATE            0x400
#define NLM_F_DUMP              (NLM_F_ROOT | NLM_F_MATCH)

/* nlmsg_type values. */
#define NLMSG_NOOP              1
#define NLMSG_ERROR             2
#define NLMSG_DONE              3
#define NLMSG_OVERRUN           4

#define NLMSG_MIN_TYPE          0x10

#define MAX_LINKS               32

#define NLMSG_ALIGNTO 4
#define NLMSG_ALIGN(SIZE) ROUND_UP(SIZE, NLMSG_ALIGNTO)

#define NLA_ALIGNTO 4
#define NLA_ALIGN(SIZE) ROUND_UP(SIZE, NLA_ALIGNTO)

typedef struct ovs_header OVS_HDR, *POVS_HDR;

typedef struct _NL_MSG_HDR {
    UINT32 nlmsgLen;
    UINT16 nlmsgType;
    UINT16 nlmsgFlags;
    UINT32 nlmsgSeq;
    UINT32 nlmsgPid;
} NL_MSG_HDR, *PNL_MSG_HDR;
BUILD_ASSERT_DECL(sizeof(NL_MSG_HDR) == 16);

typedef struct _NlMsgErr
{
    INT error;
    NL_MSG_HDR msg;
} NL_MSG_ERR, *PNL_MSG_ERR;
BUILD_ASSERT_DECL(sizeof(NL_MSG_ERR) == 20);

typedef struct _GENL_MSG_HDR {
    UINT8 cmd;
    UINT8 version;
    UINT16 reserved;
} GENL_MSG_HDR, *PGENL_MDG_HDR;
BUILD_ASSERT_DECL(sizeof(GENL_MSG_HDR) == 4);

/* Netlink attributes */
typedef struct _NL_ATTR {
    UINT16 nlaLen;
    UINT16 nlaType;
} NL_ATTR, *PNL_ATTR;
BUILD_ASSERT_DECL(sizeof(NL_ATTR) == 4);

#ifndef NLA_TYPE_MASK
#define NLA_F_NESTED        (1 << 15)
#define NLA_F_NET_BYTEORDER (1 << 14)
#define NLA_TYPE_MASK       ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
#endif

#define NLMSG_HDRLEN ((INT) NLMSG_ALIGN(sizeof(NL_MSG_HDR)))
#define GENL_HDRLEN NLMSG_ALIGN(sizeof(GENL_MSG_HDR))
#define OVS_HDRLEN NLMSG_ALIGN(sizeof(OVS_HDR))
#define NLA_HDRLEN ((INT) NLA_ALIGN(sizeof(NL_ATTR)))

#endif /* NetlinProto.h */