libnl 3.5.0

netlink-kernel.h
1 #ifndef __NETLINK_KERNEL_H_
2 #define __NETLINK_KERNEL_H_
3
4 #if 0
5
6 /*
7 * FIXME: Goal is to preseve the documentation but make it simple
8 * to keep linux/netlink.h in sync. Maybe use named documentation
9 * sections.
10 */
11
12 /**
13 * Netlink socket address
14 * @ingroup nl
15 */
16 struct sockaddr_nl
17 {
18 /** socket family (AF_NETLINK) */
19 sa_family_t nl_family;
20
21 /** Padding (unused) */
22 unsigned short nl_pad;
23
24 /** Unique process ID */
25 uint32_t nl_pid;
26
27 /** Multicast group subscriptions */
28 uint32_t nl_groups;
29 };
30
31 /**
32 * @addtogroup msg
33 * @{
34 */
35
36
37 /**
38 * Netlink message header
39 */
40 struct nlmsghdr
41 {
42 /** Length of message including header and padding. */
43 uint32_t nlmsg_len;
44
45 /** Message type (content type) */
46 uint16_t nlmsg_type;
47
48 /** Message flags */
49 uint16_t nlmsg_flags;
50
51 /** Sequence number of message \see core_sk_seq_num. */
52 uint32_t nlmsg_seq;
53
54 /** Netlink port */
55 uint32_t nlmsg_pid;
56 };
57
58 /**
59 * @name Standard message flags
60 * @{
61 */
62
63 /**
64 * Must be set on all request messages (typically from user space to
65 * kernel space).
66 */
67 #define NLM_F_REQUEST 1
68
69 /**
70 * Indicates the message is part of a multipart message terminated
71 * by NLMSG_DONE.
72 */
73 #define NLM_F_MULTI 2
74
75 /**
76 * Request for an acknowledgment on success.
77 */
78 #define NLM_F_ACK 4
79
80 /**
81 * Echo this request
82 */
83 #define NLM_F_ECHO 8
84
85 /** @} */
86
87 /**
88 * @name Additional message flags for GET requests
89 * @{
90 */
91
92 /**
93 * Return the complete table instead of a single entry.
94 */
95 #define NLM_F_ROOT 0x100
96
97 /**
98 * Return all entries matching criteria passed in message content.
99 */
100 #define NLM_F_MATCH 0x200
101
102 /**
103 * Return an atomic snapshot of the table being referenced. This
104 * may require special privileges because it has the potential to
105 * interrupt service in the FE for a longer time.
106 */
107 #define NLM_F_ATOMIC 0x400
108
109 /**
110 * Dump all entries
111 */
112 #define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
113
114 /** @} */
115
116 /**
117 * @name Additional messsage flags for NEW requests
118 * @{
119 */
120
121 /**
122 * Replace existing matching config object with this request.
123 */
124 #define NLM_F_REPLACE 0x100
125
126 /**
127 * Don't replace the config object if it already exists.
128 */
129 #define NLM_F_EXCL 0x200
130
131 /**
132 * Create config object if it doesn't already exist.
133 */
134 #define NLM_F_CREATE 0x400
135
136 /**
137 * Add to the end of the object list.
138 */
139 #define NLM_F_APPEND 0x800
140
141 /** @} */
142
143 /**
144 * @name Standard Message types
145 * @{
146 */
147
148 /**
149 * No operation, message must be ignored
150 */
151 #define NLMSG_NOOP 0x1
152
153 /**
154 * The message signals an error and the payload contains a nlmsgerr
155 * structure. This can be looked at as a NACK and typically it is
156 * from FEC to CPC.
157 */
158 #define NLMSG_ERROR 0x2
159
160 /**
161 * Message terminates a multipart message.
162 */
163 #define NLMSG_DONE 0x3
164
165 /**
166 * The message signals that data got lost
167 */
168 #define NLMSG_OVERRUN 0x4
169
170 /**
171 * Lower limit of reserved message types
172 */
173 #define NLMSG_MIN_TYPE 0x10
174
175 /** @} */
176
177 /**
178 * Netlink error message header
179 */
180 struct nlmsgerr
181 {
182 /** Error code (errno number) */
183 int error;
184
185 /** Original netlink message causing the error */
186 struct nlmsghdr msg;
187 };
188
189 struct nl_pktinfo
190 {
191 __u32 group;
192 };
193
194 /**
195 * Netlink alignment constant, all boundries within messages must be align to this.
196 *
197 * See \ref core_msg_fmt_align for more information on message alignment.
198 */
199 #define NLMSG_ALIGNTO 4
200
201 /**
202 * Returns \p len properly aligned to NLMSG_ALIGNTO.
203 *
204 * See \ref core_msg_fmt_align for more information on message alignment.
205 */
206 #define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
207
208 /**
209 * Length of a netlink message header including padding.
210 *
211 * See \ref core_msg_fmt_align for more information on message alignment.
212 */
213 #define NLMSG_HDRLEN ((int) NLMSG_ALIGN(sizeof(struct nlmsghdr)))
214
215 /** @} */
216
217 /**
218 * @addtogroup attr
219 * @{
220 */
221
222 /*
223 */
224
225 /**
226 * Netlink attribute structure
227 *
228 * @code
229 * <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
230 * +---------------------+- - -+- - - - - - - - - -+- - -+
231 * | Header | Pad | Payload | Pad |
232 * | (struct nlattr) | ing | | ing |
233 * +---------------------+- - -+- - - - - - - - - -+- - -+
234 * <-------------- nlattr->nla_len -------------->
235 * @endcode
236 */
237 struct nlattr {
238 /**
239 * Attribute length in bytes including header
240 */
241 __u16 nla_len;
242
243 /**
244 * Netlink attribute type
245 */
246 __u16 nla_type;
247 };
248
249 /**
250 * @name Attribute Type Flags
251 *
252 * @code
253 * nla_type (16 bits)
254 * +---+---+-------------------------------+
255 * | N | O | Attribute Type |
256 * +---+---+-------------------------------+
257 * N := Carries nested attributes
258 * O := Payload stored in network byte order
259 * @endcode
260 *
261 * @note The N and O flag are mutually exclusive.
262 *
263 * @{
264 */
265
266 /*
267 */
268 #define NLA_F_NESTED (1 << 15)
269 #define NLA_F_NET_BYTEORDER (1 << 14)
270 #define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
271
272 /** @} */
273
274 #define NLA_ALIGNTO 4
275
276 /**
277 * Returns \p len properly aligned to NLA_ALIGNTO.
278 *
279 * See \ref core_msg_fmt_align for more information on message alignment.
280 */
281 #define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
282
283 /**
284 * Length of a netlink attribute header including padding.
285 *
286 * See \ref core_msg_fmt_align for more information on message alignment.
287 */
288 #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
289
290 /** @} */
291
292 #endif
293 #endif /* __LINUX_NETLINK_H */
nla_type
int nla_type(const struct nlattr *nla)
Return type of the attribute.
Definition: attr.c:110
nla_len
int nla_len(const struct nlattr *nla)
Return length of the payload .
Definition: attr.c:132