Import from old repository commit 61ef2b42a9c4ba8e1600f15bb0236765edc2ad45.
[cascardo/ovs.git] / lib / netlink-protocol.h
1 /*
2  * Copyright (c) 2008 Nicira Networks.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef NETLINK_PROTOCOL_H
18 #define NETLINK_PROTOCOL_H 1
19
20 /* Netlink protocol definitions.
21  *
22  * These definitions are equivalent to those in the Linux 2.6 kernel headers,
23  * without requiring those headers to be available. */
24
25 #include <stdint.h>
26 #include <sys/socket.h>
27 #include "util.h"
28
29 #define NETLINK_GENERIC         16
30
31 struct sockaddr_nl {
32     sa_family_t nl_family;
33     unsigned short int nl_pad;
34     uint32_t nl_pid;
35     uint32_t nl_groups;
36 };
37 BUILD_ASSERT_DECL(sizeof(struct sockaddr_nl) == 12);
38
39 /* nlmsg_flags bits. */
40 #define NLM_F_REQUEST           0x001
41 #define NLM_F_MULTI             0x002
42 #define NLM_F_ACK               0x004
43 #define NLM_F_ECHO              0x008
44
45 #define NLM_F_ROOT              0x100
46 #define NLM_F_MATCH             0x200
47 #define NLM_F_ATOMIC            0x400
48 #define NLM_F_DUMP              (NLM_F_ROOT | NLM_F_MATCH)
49
50 /* nlmsg_type values. */
51 #define NLMSG_NOOP              1
52 #define NLMSG_ERROR             2
53 #define NLMSG_DONE              3
54 #define NLMSG_OVERRUN           4
55
56 #define NLMSG_MIN_TYPE          0x10
57
58 struct nlmsghdr {
59     uint32_t nlmsg_len;
60     uint16_t nlmsg_type;
61     uint16_t nlmsg_flags;
62     uint32_t nlmsg_seq;
63     uint32_t nlmsg_pid;
64 };
65 BUILD_ASSERT_DECL(sizeof(struct nlmsghdr) == 16);
66
67 #define NLMSG_ALIGNTO 4
68 #define NLMSG_ALIGN(SIZE) ROUND_UP(SIZE, NLMSG_ALIGNTO)
69 #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
70
71 struct nlmsgerr
72 {
73         int error;
74         struct nlmsghdr msg;
75 };
76 BUILD_ASSERT_DECL(sizeof(struct nlmsgerr) == 20);
77
78 #define NETLINK_ADD_MEMBERSHIP  1
79 #define NETLINK_DROP_MEMBERSHIP 2
80 #define NETLINK_PKTINFO         3
81
82 struct genlmsghdr {
83     uint8_t cmd;
84     uint8_t version;
85     uint16_t reserved;
86 };
87 BUILD_ASSERT_DECL(sizeof(struct genlmsghdr) == 4);
88
89 #define GENL_HDRLEN NLMSG_ALIGN(sizeof(struct genlmsghdr))
90
91 struct nlattr {
92     uint16_t nla_len;
93     uint16_t nla_type;
94 };
95 BUILD_ASSERT_DECL(sizeof(struct nlattr) == 4);
96
97 #define NLA_ALIGNTO 4
98 #define NLA_ALIGN(SIZE) ROUND_UP(SIZE, NLA_ALIGNTO)
99 #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
100
101 #define GENL_MIN_ID     NLMSG_MIN_TYPE
102 #define GENL_MAX_ID     1023
103
104 #define GENL_ID_CTRL            NLMSG_MIN_TYPE
105
106 enum {
107         CTRL_CMD_UNSPEC,
108         CTRL_CMD_NEWFAMILY,
109         CTRL_CMD_DELFAMILY,
110         CTRL_CMD_GETFAMILY,
111         CTRL_CMD_NEWOPS,
112         CTRL_CMD_DELOPS,
113         CTRL_CMD_GETOPS,
114         __CTRL_CMD_MAX,
115 };
116
117 #define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)
118
119 enum {
120         CTRL_ATTR_UNSPEC,
121         CTRL_ATTR_FAMILY_ID,
122         CTRL_ATTR_FAMILY_NAME,
123         CTRL_ATTR_VERSION,
124         CTRL_ATTR_HDRSIZE,
125         CTRL_ATTR_MAXATTR,
126         CTRL_ATTR_OPS,
127         __CTRL_ATTR_MAX,
128 };
129
130 #define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)
131
132 enum {
133         CTRL_ATTR_OP_UNSPEC,
134         CTRL_ATTR_OP_ID,
135         CTRL_ATTR_OP_FLAGS,
136         __CTRL_ATTR_OP_MAX,
137 };
138
139 #define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1)
140
141 #endif /* netlink-protocol.h */