libmnl: add some upstream fixes
[openwrt/svn-archive/archive.git] / package / libs / libmnl / patches / 100-upstream-fixes.patch
1 diff --git a/configure.ac b/configure.ac
2 index 718ab1c..313a015 100644
3 --- a/configure.ac
4 +++ b/configure.ac
5 @@ -27,5 +27,5 @@ regular_CFLAGS="-Wall -Waggregate-return -Wmissing-declarations \
6 -Wformat=2 -pipe"
7 AC_SUBST([regular_CPPFLAGS])
8 AC_SUBST([regular_CFLAGS])
9 -AC_CONFIG_FILES([Makefile src/Makefile include/Makefile include/libmnl/Makefile include/linux/Makefile examples/Makefile examples/genl/Makefile examples/netfilter/Makefile examples/rtnl/Makefile libmnl.pc doxygen.cfg])
10 +AC_CONFIG_FILES([Makefile src/Makefile include/Makefile include/libmnl/Makefile include/linux/Makefile include/linux/netfilter/Makefile examples/Makefile examples/genl/Makefile examples/netfilter/Makefile examples/rtnl/Makefile libmnl.pc doxygen.cfg])
11 AC_OUTPUT
12 diff --git a/include/libmnl/libmnl.h b/include/libmnl/libmnl.h
13 index a647fd9..223709c 100644
14 --- a/include/libmnl/libmnl.h
15 +++ b/include/libmnl/libmnl.h
16 @@ -1,14 +1,9 @@
17 #ifndef _LIBMNL_H_
18 #define _LIBMNL_H_
19
20 -#ifdef __cplusplus
21 -# include <cstdio>
22 -# include <cstdint>
23 -#else
24 -# include <stdbool.h> /* not in C++ */
25 -# include <stdio.h>
26 -# include <stdint.h>
27 -#endif
28 +#include <stdbool.h>
29 +#include <stdio.h>
30 +#include <stdint.h>
31 #include <unistd.h>
32 #include <sys/socket.h> /* for sa_family_t */
33 #include <linux/netlink.h>
34 diff --git a/include/linux/Makefile.am b/include/linux/Makefile.am
35 index 2d02887..08c600b 100644
36 --- a/include/linux/Makefile.am
37 +++ b/include/linux/Makefile.am
38 @@ -1 +1,2 @@
39 -noinst_HEADERS = netlink.h
40 +SUBDIRS = netfilter
41 +noinst_HEADERS = netlink.h socket.h
42 diff --git a/include/linux/netfilter/Makefile.am b/include/linux/netfilter/Makefile.am
43 new file mode 100644
44 index 0000000..64a975e
45 --- /dev/null
46 +++ b/include/linux/netfilter/Makefile.am
47 @@ -0,0 +1 @@
48 +noinst_HEADERS = nfnetlink_conntrack.h
49 diff --git a/include/linux/netfilter/nfnetlink_conntrack.h b/include/linux/netfilter/nfnetlink_conntrack.h
50 new file mode 100644
51 index 0000000..08fabc6
52 --- /dev/null
53 +++ b/include/linux/netfilter/nfnetlink_conntrack.h
54 @@ -0,0 +1,252 @@
55 +#ifndef _IPCONNTRACK_NETLINK_H
56 +#define _IPCONNTRACK_NETLINK_H
57 +#include <linux/netfilter/nfnetlink.h>
58 +
59 +enum cntl_msg_types {
60 + IPCTNL_MSG_CT_NEW,
61 + IPCTNL_MSG_CT_GET,
62 + IPCTNL_MSG_CT_DELETE,
63 + IPCTNL_MSG_CT_GET_CTRZERO,
64 + IPCTNL_MSG_CT_GET_STATS_CPU,
65 + IPCTNL_MSG_CT_GET_STATS,
66 + IPCTNL_MSG_CT_GET_DYING,
67 + IPCTNL_MSG_CT_GET_UNCONFIRMED,
68 +
69 + IPCTNL_MSG_MAX
70 +};
71 +
72 +enum ctnl_exp_msg_types {
73 + IPCTNL_MSG_EXP_NEW,
74 + IPCTNL_MSG_EXP_GET,
75 + IPCTNL_MSG_EXP_DELETE,
76 + IPCTNL_MSG_EXP_GET_STATS_CPU,
77 +
78 + IPCTNL_MSG_EXP_MAX
79 +};
80 +
81 +
82 +enum ctattr_type {
83 + CTA_UNSPEC,
84 + CTA_TUPLE_ORIG,
85 + CTA_TUPLE_REPLY,
86 + CTA_STATUS,
87 + CTA_PROTOINFO,
88 + CTA_HELP,
89 + CTA_NAT_SRC,
90 +#define CTA_NAT CTA_NAT_SRC /* backwards compatibility */
91 + CTA_TIMEOUT,
92 + CTA_MARK,
93 + CTA_COUNTERS_ORIG,
94 + CTA_COUNTERS_REPLY,
95 + CTA_USE,
96 + CTA_ID,
97 + CTA_NAT_DST,
98 + CTA_TUPLE_MASTER,
99 + CTA_NAT_SEQ_ADJ_ORIG,
100 + CTA_NAT_SEQ_ADJ_REPLY,
101 + CTA_SECMARK, /* obsolete */
102 + CTA_ZONE,
103 + CTA_SECCTX,
104 + CTA_TIMESTAMP,
105 + CTA_MARK_MASK,
106 + CTA_LABELS,
107 + CTA_LABELS_MASK,
108 + __CTA_MAX
109 +};
110 +#define CTA_MAX (__CTA_MAX - 1)
111 +
112 +enum ctattr_tuple {
113 + CTA_TUPLE_UNSPEC,
114 + CTA_TUPLE_IP,
115 + CTA_TUPLE_PROTO,
116 + __CTA_TUPLE_MAX
117 +};
118 +#define CTA_TUPLE_MAX (__CTA_TUPLE_MAX - 1)
119 +
120 +enum ctattr_ip {
121 + CTA_IP_UNSPEC,
122 + CTA_IP_V4_SRC,
123 + CTA_IP_V4_DST,
124 + CTA_IP_V6_SRC,
125 + CTA_IP_V6_DST,
126 + __CTA_IP_MAX
127 +};
128 +#define CTA_IP_MAX (__CTA_IP_MAX - 1)
129 +
130 +enum ctattr_l4proto {
131 + CTA_PROTO_UNSPEC,
132 + CTA_PROTO_NUM,
133 + CTA_PROTO_SRC_PORT,
134 + CTA_PROTO_DST_PORT,
135 + CTA_PROTO_ICMP_ID,
136 + CTA_PROTO_ICMP_TYPE,
137 + CTA_PROTO_ICMP_CODE,
138 + CTA_PROTO_ICMPV6_ID,
139 + CTA_PROTO_ICMPV6_TYPE,
140 + CTA_PROTO_ICMPV6_CODE,
141 + __CTA_PROTO_MAX
142 +};
143 +#define CTA_PROTO_MAX (__CTA_PROTO_MAX - 1)
144 +
145 +enum ctattr_protoinfo {
146 + CTA_PROTOINFO_UNSPEC,
147 + CTA_PROTOINFO_TCP,
148 + CTA_PROTOINFO_DCCP,
149 + CTA_PROTOINFO_SCTP,
150 + __CTA_PROTOINFO_MAX
151 +};
152 +#define CTA_PROTOINFO_MAX (__CTA_PROTOINFO_MAX - 1)
153 +
154 +enum ctattr_protoinfo_tcp {
155 + CTA_PROTOINFO_TCP_UNSPEC,
156 + CTA_PROTOINFO_TCP_STATE,
157 + CTA_PROTOINFO_TCP_WSCALE_ORIGINAL,
158 + CTA_PROTOINFO_TCP_WSCALE_REPLY,
159 + CTA_PROTOINFO_TCP_FLAGS_ORIGINAL,
160 + CTA_PROTOINFO_TCP_FLAGS_REPLY,
161 + __CTA_PROTOINFO_TCP_MAX
162 +};
163 +#define CTA_PROTOINFO_TCP_MAX (__CTA_PROTOINFO_TCP_MAX - 1)
164 +
165 +enum ctattr_protoinfo_dccp {
166 + CTA_PROTOINFO_DCCP_UNSPEC,
167 + CTA_PROTOINFO_DCCP_STATE,
168 + CTA_PROTOINFO_DCCP_ROLE,
169 + CTA_PROTOINFO_DCCP_HANDSHAKE_SEQ,
170 + __CTA_PROTOINFO_DCCP_MAX,
171 +};
172 +#define CTA_PROTOINFO_DCCP_MAX (__CTA_PROTOINFO_DCCP_MAX - 1)
173 +
174 +enum ctattr_protoinfo_sctp {
175 + CTA_PROTOINFO_SCTP_UNSPEC,
176 + CTA_PROTOINFO_SCTP_STATE,
177 + CTA_PROTOINFO_SCTP_VTAG_ORIGINAL,
178 + CTA_PROTOINFO_SCTP_VTAG_REPLY,
179 + __CTA_PROTOINFO_SCTP_MAX
180 +};
181 +#define CTA_PROTOINFO_SCTP_MAX (__CTA_PROTOINFO_SCTP_MAX - 1)
182 +
183 +enum ctattr_counters {
184 + CTA_COUNTERS_UNSPEC,
185 + CTA_COUNTERS_PACKETS, /* 64bit counters */
186 + CTA_COUNTERS_BYTES, /* 64bit counters */
187 + CTA_COUNTERS32_PACKETS, /* old 32bit counters, unused */
188 + CTA_COUNTERS32_BYTES, /* old 32bit counters, unused */
189 + __CTA_COUNTERS_MAX
190 +};
191 +#define CTA_COUNTERS_MAX (__CTA_COUNTERS_MAX - 1)
192 +
193 +enum ctattr_tstamp {
194 + CTA_TIMESTAMP_UNSPEC,
195 + CTA_TIMESTAMP_START,
196 + CTA_TIMESTAMP_STOP,
197 + __CTA_TIMESTAMP_MAX
198 +};
199 +#define CTA_TIMESTAMP_MAX (__CTA_TIMESTAMP_MAX - 1)
200 +
201 +enum ctattr_nat {
202 + CTA_NAT_UNSPEC,
203 + CTA_NAT_V4_MINIP,
204 +#define CTA_NAT_MINIP CTA_NAT_V4_MINIP
205 + CTA_NAT_V4_MAXIP,
206 +#define CTA_NAT_MAXIP CTA_NAT_V4_MAXIP
207 + CTA_NAT_PROTO,
208 + CTA_NAT_V6_MINIP,
209 + CTA_NAT_V6_MAXIP,
210 + __CTA_NAT_MAX
211 +};
212 +#define CTA_NAT_MAX (__CTA_NAT_MAX - 1)
213 +
214 +enum ctattr_protonat {
215 + CTA_PROTONAT_UNSPEC,
216 + CTA_PROTONAT_PORT_MIN,
217 + CTA_PROTONAT_PORT_MAX,
218 + __CTA_PROTONAT_MAX
219 +};
220 +#define CTA_PROTONAT_MAX (__CTA_PROTONAT_MAX - 1)
221 +
222 +enum ctattr_natseq {
223 + CTA_NAT_SEQ_UNSPEC,
224 + CTA_NAT_SEQ_CORRECTION_POS,
225 + CTA_NAT_SEQ_OFFSET_BEFORE,
226 + CTA_NAT_SEQ_OFFSET_AFTER,
227 + __CTA_NAT_SEQ_MAX
228 +};
229 +#define CTA_NAT_SEQ_MAX (__CTA_NAT_SEQ_MAX - 1)
230 +
231 +enum ctattr_expect {
232 + CTA_EXPECT_UNSPEC,
233 + CTA_EXPECT_MASTER,
234 + CTA_EXPECT_TUPLE,
235 + CTA_EXPECT_MASK,
236 + CTA_EXPECT_TIMEOUT,
237 + CTA_EXPECT_ID,
238 + CTA_EXPECT_HELP_NAME,
239 + CTA_EXPECT_ZONE,
240 + CTA_EXPECT_FLAGS,
241 + CTA_EXPECT_CLASS,
242 + CTA_EXPECT_NAT,
243 + CTA_EXPECT_FN,
244 + __CTA_EXPECT_MAX
245 +};
246 +#define CTA_EXPECT_MAX (__CTA_EXPECT_MAX - 1)
247 +
248 +enum ctattr_expect_nat {
249 + CTA_EXPECT_NAT_UNSPEC,
250 + CTA_EXPECT_NAT_DIR,
251 + CTA_EXPECT_NAT_TUPLE,
252 + __CTA_EXPECT_NAT_MAX
253 +};
254 +#define CTA_EXPECT_NAT_MAX (__CTA_EXPECT_NAT_MAX - 1)
255 +
256 +enum ctattr_help {
257 + CTA_HELP_UNSPEC,
258 + CTA_HELP_NAME,
259 + CTA_HELP_INFO,
260 + __CTA_HELP_MAX
261 +};
262 +#define CTA_HELP_MAX (__CTA_HELP_MAX - 1)
263 +
264 +enum ctattr_secctx {
265 + CTA_SECCTX_UNSPEC,
266 + CTA_SECCTX_NAME,
267 + __CTA_SECCTX_MAX
268 +};
269 +#define CTA_SECCTX_MAX (__CTA_SECCTX_MAX - 1)
270 +
271 +enum ctattr_stats_cpu {
272 + CTA_STATS_UNSPEC,
273 + CTA_STATS_SEARCHED,
274 + CTA_STATS_FOUND,
275 + CTA_STATS_NEW,
276 + CTA_STATS_INVALID,
277 + CTA_STATS_IGNORE,
278 + CTA_STATS_DELETE,
279 + CTA_STATS_DELETE_LIST,
280 + CTA_STATS_INSERT,
281 + CTA_STATS_INSERT_FAILED,
282 + CTA_STATS_DROP,
283 + CTA_STATS_EARLY_DROP,
284 + CTA_STATS_ERROR,
285 + CTA_STATS_SEARCH_RESTART,
286 + __CTA_STATS_MAX,
287 +};
288 +#define CTA_STATS_MAX (__CTA_STATS_MAX - 1)
289 +
290 +enum ctattr_stats_global {
291 + CTA_STATS_GLOBAL_UNSPEC,
292 + CTA_STATS_GLOBAL_ENTRIES,
293 + __CTA_STATS_GLOBAL_MAX,
294 +};
295 +#define CTA_STATS_GLOBAL_MAX (__CTA_STATS_GLOBAL_MAX - 1)
296 +
297 +enum ctattr_expect_stats {
298 + CTA_STATS_EXP_UNSPEC,
299 + CTA_STATS_EXP_NEW,
300 + CTA_STATS_EXP_CREATE,
301 + CTA_STATS_EXP_DELETE,
302 + __CTA_STATS_EXP_MAX,
303 +};
304 +#define CTA_STATS_EXP_MAX (__CTA_STATS_EXP_MAX - 1)
305 +
306 +#endif /* _IPCONNTRACK_NETLINK_H */
307 diff --git a/include/linux/netlink.h b/include/linux/netlink.h
308 index f55ed8c..ced0e1a 100644
309 --- a/include/linux/netlink.h
310 +++ b/include/linux/netlink.h
311 @@ -1,14 +1,14 @@
312 #ifndef __LINUX_NETLINK_H
313 #define __LINUX_NETLINK_H
314
315 -#include <linux/socket.h> /* for sa_family_t */
316 +#include <linux/socket.h> /* for __kernel_sa_family_t */
317 #include <linux/types.h>
318
319 #define NETLINK_ROUTE 0 /* Routing/device hook */
320 #define NETLINK_UNUSED 1 /* Unused number */
321 #define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */
322 -#define NETLINK_FIREWALL 3 /* Firewalling hook */
323 -#define NETLINK_INET_DIAG 4 /* INET socket monitoring */
324 +#define NETLINK_FIREWALL 3 /* Unused number, formerly ip_queue */
325 +#define NETLINK_SOCK_DIAG 4 /* socket monitoring */
326 #define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */
327 #define NETLINK_XFRM 6 /* ipsec */
328 #define NETLINK_SELINUX 7 /* SELinux event notifications */
329 @@ -24,11 +24,15 @@
330 /* leave room for NETLINK_DM (DM Events) */
331 #define NETLINK_SCSITRANSPORT 18 /* SCSI Transports */
332 #define NETLINK_ECRYPTFS 19
333 +#define NETLINK_RDMA 20
334 +#define NETLINK_CRYPTO 21 /* Crypto layer */
335 +
336 +#define NETLINK_INET_DIAG NETLINK_SOCK_DIAG
337
338 #define MAX_LINKS 32
339
340 struct sockaddr_nl {
341 - sa_family_t nl_family; /* AF_NETLINK */
342 + __kernel_sa_family_t nl_family; /* AF_NETLINK */
343 unsigned short nl_pad; /* zero */
344 __u32 nl_pid; /* port ID */
345 __u32 nl_groups; /* multicast groups mask */
346 @@ -48,6 +52,7 @@ struct nlmsghdr {
347 #define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */
348 #define NLM_F_ACK 4 /* Reply with ack, with zero or error code */
349 #define NLM_F_ECHO 8 /* Echo this request */
350 +#define NLM_F_DUMP_INTR 16 /* Dump was inconsistent due to sequence change */
351
352 /* Modifiers to GET request */
353 #define NLM_F_ROOT 0x100 /* specify tree root */
354 @@ -145,4 +150,4 @@ struct nlattr {
355 #define NLA_HDRLEN ((int) NLA_ALIGN(sizeof(struct nlattr)))
356
357
358 -#endif /* __LINUX_NETLINK_H */
359 +#endif /* __LINUX_NETLINK_H */
360 diff --git a/include/linux/socket.h b/include/linux/socket.h
361 new file mode 100644
362 index 0000000..8c1e501
363 --- /dev/null
364 +++ b/include/linux/socket.h
365 @@ -0,0 +1,21 @@
366 +#ifndef _LINUX_SOCKET_H
367 +#define _LINUX_SOCKET_H
368 +
369 +/*
370 + * Desired design of maximum size and alignment (see RFC2553)
371 + */
372 +#define _K_SS_MAXSIZE 128 /* Implementation specific max size */
373 +#define _K_SS_ALIGNSIZE (__alignof__ (struct sockaddr *))
374 + /* Implementation specific desired alignment */
375 +
376 +typedef unsigned short __kernel_sa_family_t;
377 +
378 +struct __kernel_sockaddr_storage {
379 + __kernel_sa_family_t ss_family; /* address family */
380 + /* Following field(s) are implementation specific */
381 + char __data[_K_SS_MAXSIZE - sizeof(unsigned short)];
382 + /* space to achieve desired size, */
383 + /* _SS_MAXSIZE value minus size of ss_family */
384 +} __attribute__ ((aligned(_K_SS_ALIGNSIZE))); /* force desired alignment */
385 +
386 +#endif /* _LINUX_SOCKET_H */
387 diff --git a/src/attr.c b/src/attr.c
388 index 1136c50..c3c57e6 100644
389 --- a/src/attr.c
390 +++ b/src/attr.c
391 @@ -200,6 +200,7 @@ static const size_t mnl_attr_data_type_len[MNL_TYPE_MAX] = {
392 [MNL_TYPE_U16] = sizeof(uint16_t),
393 [MNL_TYPE_U32] = sizeof(uint32_t),
394 [MNL_TYPE_U64] = sizeof(uint64_t),
395 + [MNL_TYPE_MSECS] = sizeof(uint64_t),
396 };
397
398 /**
399 diff --git a/src/callback.c b/src/callback.c
400 index 6337acc..f023401 100644
401 --- a/src/callback.c
402 +++ b/src/callback.c
403 @@ -65,6 +65,12 @@ __mnl_cb_run(const void *buf, size_t numbytes, unsigned int seq,
404 return -1;
405 }
406
407 + /* dump was interrupted */
408 + if (nlh->nlmsg_flags & NLM_F_DUMP_INTR) {
409 + errno = EINTR;
410 + return -1;
411 + }
412 +
413 /* netlink data message handling */
414 if (nlh->nlmsg_type >= NLMSG_MIN_TYPE) {
415 if (cb_data){
416