100-upstream-fixes.patch 11 KB

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