uringmachine 0.15 → 0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +3 -0
  3. data/.gitmodules +4 -0
  4. data/CHANGELOG.md +12 -0
  5. data/TODO.md +12 -3
  6. data/examples/bm_send.rb +86 -0
  7. data/ext/um/um.c +28 -1
  8. data/ext/um/um.h +3 -0
  9. data/ext/um/um_class.c +17 -0
  10. data/ext/um/um_stream_class.c +0 -1
  11. data/ext/um/um_utils.c +38 -15
  12. data/lib/uringmachine/version.rb +1 -1
  13. data/lib/uringmachine.rb +4 -3
  14. data/test/test_um.rb +76 -0
  15. data/vendor/libressl/.github/scripts/changelog.sh +74 -0
  16. data/vendor/libressl/.github/workflows/android.yml +35 -0
  17. data/vendor/libressl/.github/workflows/cifuzz.yml +33 -0
  18. data/vendor/libressl/.github/workflows/cmake-config.yml +98 -0
  19. data/vendor/libressl/.github/workflows/coverity.yml +69 -0
  20. data/vendor/libressl/.github/workflows/emscripten.yml +71 -0
  21. data/vendor/libressl/.github/workflows/fedora-rawhide.yml +39 -0
  22. data/vendor/libressl/.github/workflows/freebsd.yml +71 -0
  23. data/vendor/libressl/.github/workflows/linux.yml +71 -0
  24. data/vendor/libressl/.github/workflows/macos.yml +37 -0
  25. data/vendor/libressl/.github/workflows/release.yml +81 -0
  26. data/vendor/libressl/.github/workflows/rust-openssl.yml +47 -0
  27. data/vendor/libressl/.github/workflows/solaris.yml +37 -0
  28. data/vendor/libressl/.github/workflows/windows.yml +70 -0
  29. data/vendor/libressl/.gitignore +333 -0
  30. data/vendor/libressl/CMakeLists.txt +581 -0
  31. data/vendor/libressl/COPYING +133 -0
  32. data/vendor/libressl/ChangeLog +3280 -0
  33. data/vendor/libressl/FindLibreSSL.cmake +232 -0
  34. data/vendor/libressl/LibreSSLConfig.cmake.in +36 -0
  35. data/vendor/libressl/Makefile.am +60 -0
  36. data/vendor/libressl/Makefile.am.common +20 -0
  37. data/vendor/libressl/OPENBSD_BRANCH +1 -0
  38. data/vendor/libressl/README.md +238 -0
  39. data/vendor/libressl/README.mingw.md +43 -0
  40. data/vendor/libressl/apps/CMakeLists.txt +18 -0
  41. data/vendor/libressl/apps/Makefile.am +5 -0
  42. data/vendor/libressl/apps/nc/CMakeLists.txt +67 -0
  43. data/vendor/libressl/apps/nc/Makefile.am +64 -0
  44. data/vendor/libressl/apps/nc/compat/accept4.c +17 -0
  45. data/vendor/libressl/apps/nc/compat/readpassphrase.c +205 -0
  46. data/vendor/libressl/apps/nc/compat/socket.c +29 -0
  47. data/vendor/libressl/apps/nc/compat/sys/socket.h +30 -0
  48. data/vendor/libressl/apps/ocspcheck/CMakeLists.txt +44 -0
  49. data/vendor/libressl/apps/ocspcheck/Makefile.am +45 -0
  50. data/vendor/libressl/apps/ocspcheck/compat/.gitignore +0 -0
  51. data/vendor/libressl/apps/openssl/CMakeLists.txt +97 -0
  52. data/vendor/libressl/apps/openssl/Makefile.am +108 -0
  53. data/vendor/libressl/apps/openssl/apps_win.c +138 -0
  54. data/vendor/libressl/apps/openssl/certhash_win.c +13 -0
  55. data/vendor/libressl/apps/openssl/compat/clock_gettime_osx.c +26 -0
  56. data/vendor/libressl/apps/openssl/compat/poll_win.c +329 -0
  57. data/vendor/libressl/appveyor.yml +53 -0
  58. data/vendor/libressl/autogen.sh +15 -0
  59. data/vendor/libressl/check-release.sh +86 -0
  60. data/vendor/libressl/cmake_export_symbol.cmake +71 -0
  61. data/vendor/libressl/cmake_uninstall.cmake.in +36 -0
  62. data/vendor/libressl/config +17 -0
  63. data/vendor/libressl/configure.ac +165 -0
  64. data/vendor/libressl/crypto/CMakeLists.txt +863 -0
  65. data/vendor/libressl/crypto/Makefile.am +962 -0
  66. data/vendor/libressl/crypto/Makefile.am.arc4random +46 -0
  67. data/vendor/libressl/crypto/Makefile.am.elf-mips +14 -0
  68. data/vendor/libressl/crypto/Makefile.am.elf-mips64 +14 -0
  69. data/vendor/libressl/crypto/Makefile.am.elf-x86_64 +35 -0
  70. data/vendor/libressl/crypto/Makefile.am.macosx-x86_64 +35 -0
  71. data/vendor/libressl/crypto/Makefile.am.masm-x86_64 +22 -0
  72. data/vendor/libressl/crypto/Makefile.am.mingw64-x86_64 +23 -0
  73. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_darwin.c +60 -0
  74. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_linux.c +62 -0
  75. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_none.c +26 -0
  76. data/vendor/libressl/crypto/arch/aarch64/crypto_cpu_caps_windows.c +36 -0
  77. data/vendor/libressl/crypto/arch/loongarch64/crypto_arch.h +21 -0
  78. data/vendor/libressl/crypto/arch/mips/crypto_arch.h +21 -0
  79. data/vendor/libressl/crypto/bn/arch/loongarch64/bn_arch.h +23 -0
  80. data/vendor/libressl/crypto/bn/arch/mips/bn_arch.h +24 -0
  81. data/vendor/libressl/crypto/compat/.gitignore +31 -0
  82. data/vendor/libressl/crypto/compat/arc4random.h +41 -0
  83. data/vendor/libressl/crypto/compat/b_win.c +55 -0
  84. data/vendor/libressl/crypto/compat/bsd-asprintf.c +96 -0
  85. data/vendor/libressl/crypto/compat/crypto_lock_win.c +56 -0
  86. data/vendor/libressl/crypto/compat/explicit_bzero_win.c +13 -0
  87. data/vendor/libressl/crypto/compat/freezero.c +32 -0
  88. data/vendor/libressl/crypto/compat/getdelim.c +78 -0
  89. data/vendor/libressl/crypto/compat/getline.c +40 -0
  90. data/vendor/libressl/crypto/compat/getopt_long.c +528 -0
  91. data/vendor/libressl/crypto/compat/getpagesize.c +18 -0
  92. data/vendor/libressl/crypto/compat/getprogname_linux.c +23 -0
  93. data/vendor/libressl/crypto/compat/getprogname_unimpl.c +7 -0
  94. data/vendor/libressl/crypto/compat/getprogname_windows.c +13 -0
  95. data/vendor/libressl/crypto/compat/posix_win.c +296 -0
  96. data/vendor/libressl/crypto/compat/syslog_r.c +19 -0
  97. data/vendor/libressl/crypto/compat/ui_openssl_win.c +334 -0
  98. data/vendor/libressl/dist.sh +22 -0
  99. data/vendor/libressl/gen-coverage-report.sh +58 -0
  100. data/vendor/libressl/gen-openbsd-tags.sh +20 -0
  101. data/vendor/libressl/include/CMakeLists.txt +61 -0
  102. data/vendor/libressl/include/Makefile.am +79 -0
  103. data/vendor/libressl/include/arch/loongarch64/opensslconf.h +150 -0
  104. data/vendor/libressl/include/arch/mips/opensslconf.h +150 -0
  105. data/vendor/libressl/include/compat/arpa/inet.h +15 -0
  106. data/vendor/libressl/include/compat/arpa/nameser.h +25 -0
  107. data/vendor/libressl/include/compat/cet.h +19 -0
  108. data/vendor/libressl/include/compat/dirent.h +17 -0
  109. data/vendor/libressl/include/compat/dirent_msvc.h +611 -0
  110. data/vendor/libressl/include/compat/endian.h +161 -0
  111. data/vendor/libressl/include/compat/err.h +95 -0
  112. data/vendor/libressl/include/compat/fcntl.h +32 -0
  113. data/vendor/libressl/include/compat/getopt.h +50 -0
  114. data/vendor/libressl/include/compat/limits.h +25 -0
  115. data/vendor/libressl/include/compat/netdb.h +10 -0
  116. data/vendor/libressl/include/compat/netinet/in.h +19 -0
  117. data/vendor/libressl/include/compat/netinet/ip.h +49 -0
  118. data/vendor/libressl/include/compat/netinet/tcp.h +10 -0
  119. data/vendor/libressl/include/compat/poll.h +63 -0
  120. data/vendor/libressl/include/compat/pthread.h +122 -0
  121. data/vendor/libressl/include/compat/readpassphrase.h +44 -0
  122. data/vendor/libressl/include/compat/resolv.h +24 -0
  123. data/vendor/libressl/include/compat/stdint.h +31 -0
  124. data/vendor/libressl/include/compat/stdio.h +65 -0
  125. data/vendor/libressl/include/compat/stdlib.h +57 -0
  126. data/vendor/libressl/include/compat/string.h +98 -0
  127. data/vendor/libressl/include/compat/sys/_null.h +18 -0
  128. data/vendor/libressl/include/compat/sys/ioctl.h +11 -0
  129. data/vendor/libressl/include/compat/sys/mman.h +19 -0
  130. data/vendor/libressl/include/compat/sys/param.h +15 -0
  131. data/vendor/libressl/include/compat/sys/queue.h +536 -0
  132. data/vendor/libressl/include/compat/sys/select.h +10 -0
  133. data/vendor/libressl/include/compat/sys/socket.h +18 -0
  134. data/vendor/libressl/include/compat/sys/stat.h +129 -0
  135. data/vendor/libressl/include/compat/sys/time.h +37 -0
  136. data/vendor/libressl/include/compat/sys/tree.h +1006 -0
  137. data/vendor/libressl/include/compat/sys/types.h +69 -0
  138. data/vendor/libressl/include/compat/sys/uio.h +17 -0
  139. data/vendor/libressl/include/compat/syslog.h +38 -0
  140. data/vendor/libressl/include/compat/time.h +59 -0
  141. data/vendor/libressl/include/compat/unistd.h +83 -0
  142. data/vendor/libressl/include/compat/win32netcompat.h +57 -0
  143. data/vendor/libressl/include/openssl/Makefile.am.tpl +45 -0
  144. data/vendor/libressl/libcrypto.pc.in +28 -0
  145. data/vendor/libressl/libressl.pub +2 -0
  146. data/vendor/libressl/libssl.pc.in +28 -0
  147. data/vendor/libressl/libtls.pc.in +28 -0
  148. data/vendor/libressl/m4/ax_add_fortify_source.m4 +80 -0
  149. data/vendor/libressl/m4/ax_check_compile_flag.m4 +53 -0
  150. data/vendor/libressl/m4/check-hardening-options.m4 +110 -0
  151. data/vendor/libressl/m4/check-libc.m4 +189 -0
  152. data/vendor/libressl/m4/check-os-options.m4 +181 -0
  153. data/vendor/libressl/m4/disable-compiler-warnings.m4 +44 -0
  154. data/vendor/libressl/man/CMakeLists.txt +26 -0
  155. data/vendor/libressl/man/links +2780 -0
  156. data/vendor/libressl/man/update_links.sh +25 -0
  157. data/vendor/libressl/openssl.pc.in +11 -0
  158. data/vendor/libressl/patches/bn_shift.patch +34 -0
  159. data/vendor/libressl/patches/crypto_arch.h.patch +34 -0
  160. data/vendor/libressl/patches/crypto_namespace.h.patch +22 -0
  161. data/vendor/libressl/patches/netcat.c.patch +178 -0
  162. data/vendor/libressl/patches/openssl.c.patch +12 -0
  163. data/vendor/libressl/patches/opensslfeatures.h.patch +49 -0
  164. data/vendor/libressl/patches/patch-amd64-crypto-cpu-caps.c.patch +20 -0
  165. data/vendor/libressl/patches/patch-i386-crypto-cpu-caps.c.patch +20 -0
  166. data/vendor/libressl/patches/speed.c.patch +114 -0
  167. data/vendor/libressl/patches/ssl_namespace.h.patch +21 -0
  168. data/vendor/libressl/patches/tls.h.patch +16 -0
  169. data/vendor/libressl/patches/tls_config.c.patch +15 -0
  170. data/vendor/libressl/patches/win32_amd64_bn_arch.h.patch +28 -0
  171. data/vendor/libressl/patches/windows_headers.patch +80 -0
  172. data/vendor/libressl/scripts/config.guess +1774 -0
  173. data/vendor/libressl/scripts/config.sub +1907 -0
  174. data/vendor/libressl/scripts/i686-w64-mingw32.cmake +9 -0
  175. data/vendor/libressl/scripts/test +210 -0
  176. data/vendor/libressl/scripts/wrap-compiler-for-flag-check +31 -0
  177. data/vendor/libressl/scripts/x86_64-w64-mingw32.cmake +9 -0
  178. data/vendor/libressl/ssl/CMakeLists.txt +183 -0
  179. data/vendor/libressl/ssl/Makefile.am +187 -0
  180. data/vendor/libressl/tests/CMakeLists.txt +970 -0
  181. data/vendor/libressl/tests/Makefile.am +944 -0
  182. data/vendor/libressl/tests/aeadtest.sh +30 -0
  183. data/vendor/libressl/tests/arc4randomforktest.sh +21 -0
  184. data/vendor/libressl/tests/asn1time_small.test +10 -0
  185. data/vendor/libressl/tests/cmake/CMakeLists.txt +52 -0
  186. data/vendor/libressl/tests/cmake/crypto.c +7 -0
  187. data/vendor/libressl/tests/cmake/ssl.c +6 -0
  188. data/vendor/libressl/tests/cmake/tls.c +6 -0
  189. data/vendor/libressl/tests/compat/pipe2.c +186 -0
  190. data/vendor/libressl/tests/dtlstest.sh +28 -0
  191. data/vendor/libressl/tests/evptest.sh +22 -0
  192. data/vendor/libressl/tests/keypairtest.sh +27 -0
  193. data/vendor/libressl/tests/mlkem_tests.sh +39 -0
  194. data/vendor/libressl/tests/ocsptest.bat +25 -0
  195. data/vendor/libressl/tests/ocsptest.sh +23 -0
  196. data/vendor/libressl/tests/openssl.cnf +29 -0
  197. data/vendor/libressl/tests/optionstest.c +381 -0
  198. data/vendor/libressl/tests/pidwraptest.c +85 -0
  199. data/vendor/libressl/tests/pidwraptest.sh +26 -0
  200. data/vendor/libressl/tests/quictest.bat +27 -0
  201. data/vendor/libressl/tests/quictest.sh +30 -0
  202. data/vendor/libressl/tests/renegotiation_test.bat +27 -0
  203. data/vendor/libressl/tests/renegotiation_test.sh +30 -0
  204. data/vendor/libressl/tests/rfc5280time_small.test +10 -0
  205. data/vendor/libressl/tests/servertest.bat +27 -0
  206. data/vendor/libressl/tests/servertest.sh +30 -0
  207. data/vendor/libressl/tests/shutdowntest.bat +27 -0
  208. data/vendor/libressl/tests/shutdowntest.sh +30 -0
  209. data/vendor/libressl/tests/ssltest.bat +32 -0
  210. data/vendor/libressl/tests/ssltest.sh +48 -0
  211. data/vendor/libressl/tests/testdsa.bat +47 -0
  212. data/vendor/libressl/tests/testdsa.sh +57 -0
  213. data/vendor/libressl/tests/testenc.bat +85 -0
  214. data/vendor/libressl/tests/testenc.sh +93 -0
  215. data/vendor/libressl/tests/testrsa.bat +47 -0
  216. data/vendor/libressl/tests/testrsa.sh +57 -0
  217. data/vendor/libressl/tests/testssl.bat +171 -0
  218. data/vendor/libressl/tests/tlstest.bat +27 -0
  219. data/vendor/libressl/tests/tlstest.sh +28 -0
  220. data/vendor/libressl/tls/CMakeLists.txt +125 -0
  221. data/vendor/libressl/tls/Makefile.am +76 -0
  222. data/vendor/libressl/tls/compat/ftruncate.c +17 -0
  223. data/vendor/libressl/tls/compat/pread.c +29 -0
  224. data/vendor/libressl/tls/compat/pwrite.c +29 -0
  225. data/vendor/libressl/update.sh +460 -0
  226. data/vendor/liburing/.github/workflows/ci.yml +8 -0
  227. data/vendor/liburing/configure +23 -2
  228. data/vendor/liburing/examples/helpers.c +1 -1
  229. data/vendor/liburing/examples/helpers.h +1 -1
  230. data/vendor/liburing/examples/reg-wait.c +3 -3
  231. data/vendor/liburing/examples/zcrx.c +5 -5
  232. data/vendor/liburing/liburing.spec +1 -1
  233. data/vendor/liburing/src/include/liburing/io_uring.h +16 -0
  234. data/vendor/liburing/src/include/liburing.h +20 -4
  235. data/vendor/liburing/src/lib.h +2 -4
  236. data/vendor/liburing/src/liburing-ffi.map +7 -0
  237. data/vendor/liburing/src/liburing.map +7 -0
  238. data/vendor/liburing/src/register.c +5 -0
  239. data/vendor/liburing/src/sanitize.c +5 -4
  240. data/vendor/liburing/src/setup.c +43 -28
  241. data/vendor/liburing/test/Makefile +7 -0
  242. data/vendor/liburing/test/cmd-discard.c +2 -2
  243. data/vendor/liburing/test/evfd-short-read.c +84 -0
  244. data/vendor/liburing/test/fdinfo-sqpoll.c +117 -0
  245. data/vendor/liburing/test/fdinfo.c +1 -1
  246. data/vendor/liburing/test/fixed-buf-merge.c +2 -2
  247. data/vendor/liburing/test/futex-kill.c +135 -0
  248. data/vendor/liburing/test/helpers.c +1 -1
  249. data/vendor/liburing/test/helpers.h +1 -1
  250. data/vendor/liburing/test/init-mem.c +50 -12
  251. data/vendor/liburing/test/io_uring_passthrough.c +25 -6
  252. data/vendor/liburing/test/msg-ring.c +123 -9
  253. data/vendor/liburing/test/recv-bundle-short-ooo.c +16 -1
  254. data/vendor/liburing/test/recv-inc-ooo.c +411 -0
  255. data/vendor/liburing/test/recv-mshot-fair.c +513 -0
  256. data/vendor/liburing/test/reg-wait.c +14 -14
  257. data/vendor/liburing/test/send-zerocopy.c +4 -4
  258. data/vendor/liburing/test/timerfd-short-read.c +81 -0
  259. data/vendor/liburing/test/timestamp.c +382 -0
  260. data/vendor/liburing/test/zcrx.c +22 -22
  261. metadata +222 -2
@@ -0,0 +1,382 @@
1
+ #include <arpa/inet.h>
2
+ #include <error.h>
3
+ #include <errno.h>
4
+ #include <inttypes.h>
5
+ #include <linux/errqueue.h>
6
+ #include <linux/ipv6.h>
7
+ #include <linux/net_tstamp.h>
8
+ #include <netinet/in.h>
9
+ #include <netinet/ip.h>
10
+ #include <netinet/udp.h>
11
+ #include <netinet/tcp.h>
12
+ #include <stdarg.h>
13
+ #include <stdbool.h>
14
+ #include <stdio.h>
15
+ #include <stdlib.h>
16
+ #include <string.h>
17
+ #include <sys/socket.h>
18
+ #include <time.h>
19
+ #include <unistd.h>
20
+ #include <assert.h>
21
+
22
+ #include "liburing.h"
23
+ #include "helpers.h"
24
+
25
+ /*
26
+ * Only sparc/hppa should have "non-standard" values for SCM_TS_OPT_ID
27
+ */
28
+ #ifndef SCM_TS_OPT_ID
29
+ #if defined(__sparc__) || defined(__sparc64__)
30
+ #define SCM_TS_OPT_ID 0x005a
31
+ #elif defined(__hppa__)
32
+ #define SCM_TS_OPT_ID 0x404C
33
+ #else
34
+ #define SCM_TS_OPT_ID 81
35
+ #endif
36
+ #endif
37
+
38
+ static const int cfg_payload_len = 10;
39
+ static uint16_t dest_port = 9000;
40
+ static uint32_t ts_opt_id = 81;
41
+ static bool cfg_use_cmsg_opt_id = false;
42
+ static char buffer[128];
43
+ static const bool verbose = false;
44
+
45
+ static struct sockaddr_in6 daddr6;
46
+
47
+ static int saved_tskey = -1;
48
+ static int saved_tskey_type = -1;
49
+
50
+ struct ctx {
51
+ int family;
52
+ int proto;
53
+ int report_opt;
54
+ int num_pkts;
55
+ };
56
+
57
+ static int validate_key(int tskey, int tstype, struct ctx *ctx)
58
+ {
59
+ int stepsize;
60
+
61
+ /* compare key for each subsequent request
62
+ * must only test for one type, the first one requested
63
+ */
64
+ if (saved_tskey == -1 || cfg_use_cmsg_opt_id)
65
+ saved_tskey_type = tstype;
66
+ else if (saved_tskey_type != tstype)
67
+ return 0;
68
+
69
+ stepsize = ctx->proto == SOCK_STREAM ? cfg_payload_len : 1;
70
+ stepsize = cfg_use_cmsg_opt_id ? 0 : stepsize;
71
+ if (tskey != saved_tskey + stepsize) {
72
+ fprintf(stderr, "ERROR: key %d, expected %d\n",
73
+ tskey, saved_tskey + stepsize);
74
+ return -EINVAL;
75
+ }
76
+
77
+ saved_tskey = tskey;
78
+ return 0;
79
+ }
80
+
81
+ static int test_prep_sock(int family, int proto, unsigned report_opt)
82
+ {
83
+ int ipproto = proto == SOCK_STREAM ? IPPROTO_TCP : IPPROTO_UDP;
84
+ unsigned int sock_opt;
85
+ int fd, val = 1;
86
+
87
+ fd = socket(family, proto, ipproto);
88
+ if (fd < 0)
89
+ error(1, errno, "socket");
90
+
91
+ if (proto == SOCK_STREAM) {
92
+ if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
93
+ (char*) &val, sizeof(val)))
94
+ error(1, 0, "setsockopt no nagle");
95
+
96
+ if (connect(fd, (void *) &daddr6, sizeof(daddr6)))
97
+ error(1, errno, "connect ipv6");
98
+ }
99
+
100
+ sock_opt = SOF_TIMESTAMPING_SOFTWARE |
101
+ SOF_TIMESTAMPING_OPT_CMSG |
102
+ SOF_TIMESTAMPING_OPT_ID;
103
+ sock_opt |= report_opt;
104
+ sock_opt |= SOF_TIMESTAMPING_OPT_TSONLY;
105
+
106
+ if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING,
107
+ (char *) &sock_opt, sizeof(sock_opt)))
108
+ error(1, 0, "setsockopt timestamping");
109
+
110
+ return fd;
111
+ }
112
+
113
+ #define MAX_PACKETS 32
114
+
115
+ struct send_req {
116
+ struct msghdr msg;
117
+ struct iovec iov;
118
+ char control[CMSG_SPACE(sizeof(uint32_t))];
119
+ };
120
+
121
+ static void queue_ts_cmd(struct io_uring *ring, int fd)
122
+ {
123
+ struct io_uring_sqe *sqe;
124
+
125
+ sqe = io_uring_get_sqe(ring);
126
+ io_uring_prep_rw(IORING_OP_URING_CMD, sqe, fd, NULL, 0, 0);
127
+ sqe->cmd_op = SOCKET_URING_OP_TX_TIMESTAMP;
128
+ sqe->user_data = 43;
129
+ }
130
+
131
+ static void queue_send(struct io_uring *ring, int fd, void *buf, struct send_req *r,
132
+ int proto)
133
+ {
134
+ struct io_uring_sqe *sqe;
135
+
136
+ r->iov.iov_base = buf;
137
+ r->iov.iov_len = cfg_payload_len;
138
+
139
+ memset(&r->msg, 0, sizeof(r->msg));
140
+ r->msg.msg_iov = &r->iov;
141
+ r->msg.msg_iovlen = 1;
142
+ if (proto == SOCK_STREAM) {
143
+ r->msg.msg_name = (void *)&daddr6;
144
+ r->msg.msg_namelen = sizeof(daddr6);
145
+ }
146
+
147
+ if (cfg_use_cmsg_opt_id) {
148
+ struct cmsghdr *cmsg;
149
+
150
+ memset(r->control, 0, sizeof(r->control));
151
+ r->msg.msg_control = r->control;
152
+ r->msg.msg_controllen = CMSG_SPACE(sizeof(uint32_t));
153
+
154
+ cmsg = CMSG_FIRSTHDR(&r->msg);
155
+ cmsg->cmsg_level = SOL_SOCKET;
156
+ cmsg->cmsg_type = SCM_TS_OPT_ID;
157
+ cmsg->cmsg_len = CMSG_LEN(sizeof(uint32_t));
158
+
159
+ *((uint32_t *)CMSG_DATA(cmsg)) = ts_opt_id;
160
+ saved_tskey = ts_opt_id;
161
+ }
162
+
163
+ sqe = io_uring_get_sqe(ring);
164
+ io_uring_prep_sendmsg(sqe, fd, &r->msg, 0);
165
+ sqe->user_data = 0;
166
+ }
167
+
168
+ static const char *get_tstype_name(int tstype)
169
+ {
170
+ if (tstype == SCM_TSTAMP_SCHED)
171
+ return "ENQ";
172
+ if (tstype == SCM_TSTAMP_SND)
173
+ return "SND";
174
+ if (tstype == SCM_TSTAMP_ACK)
175
+ return "ACK";
176
+ return "unknown";
177
+ }
178
+
179
+ static int do_test(struct ctx *ctx)
180
+ {
181
+ struct send_req reqs[MAX_PACKETS];
182
+ struct io_uring_cqe *cqe;
183
+ struct io_uring ring;
184
+ unsigned long head;
185
+ int cqes_seen = 0;
186
+ int i, fd, ret;
187
+ int ts_expected = 0, ts_got = 0;
188
+
189
+ ts_expected += !!(ctx->report_opt & SOF_TIMESTAMPING_TX_SCHED);
190
+ ts_expected += !!(ctx->report_opt & SOF_TIMESTAMPING_TX_SOFTWARE);
191
+ ts_expected += !!(ctx->report_opt & SOF_TIMESTAMPING_TX_ACK);
192
+
193
+ ret = t_create_ring(32, &ring, IORING_SETUP_CQE32);
194
+ if (ret == T_SETUP_SKIP)
195
+ return T_EXIT_SKIP;
196
+ else if (ret)
197
+ t_error(1, ret, "queue init\n");
198
+
199
+ assert(ctx->num_pkts <= MAX_PACKETS);
200
+
201
+ fd = test_prep_sock(ctx->family, ctx->proto, ctx->report_opt);
202
+ if (fd < 0)
203
+ t_error(1, fd, "can't create socket\n");
204
+
205
+ memset(buffer, 'a', cfg_payload_len);
206
+ saved_tskey = -1;
207
+
208
+ if (cfg_use_cmsg_opt_id)
209
+ saved_tskey = ts_opt_id;
210
+
211
+ for (i = 0; i < ctx->num_pkts; i++) {
212
+ queue_send(&ring, fd, buffer, &reqs[i], ctx->proto);
213
+ ret = io_uring_submit(&ring);
214
+ if (ret != 1)
215
+ t_error(1, ret, "submit failed");
216
+
217
+ ret = io_uring_wait_cqe(&ring, &cqe);
218
+ if (ret || cqe->res != cfg_payload_len) {
219
+ fprintf(stderr, "wait send cqe, %d %d, expected %d\n",
220
+ ret, cqe->res, cfg_payload_len);
221
+ return T_EXIT_FAIL;
222
+ }
223
+ io_uring_cqe_seen(&ring, cqe);
224
+ }
225
+
226
+ usleep(200000);
227
+
228
+ queue_ts_cmd(&ring, fd);
229
+ ret = io_uring_submit(&ring);
230
+ if (ret != 1)
231
+ t_error(1, ret, "submit failed");
232
+
233
+ ret = io_uring_wait_cqe(&ring, &cqe);
234
+ if (ret) {
235
+ fprintf(stderr, "wait_cqe failed %d\n", ret);
236
+ return T_EXIT_FAIL;
237
+ }
238
+
239
+ io_uring_for_each_cqe(&ring, head, cqe) {
240
+ struct io_timespec *ts;
241
+ int tskey, tstype;
242
+ bool hwts;
243
+
244
+ cqes_seen++;
245
+
246
+ if (!(cqe->flags & IORING_CQE_F_MORE)) {
247
+ if (cqe->res == -EINVAL || cqe->res == -EOPNOTSUPP)
248
+ return T_EXIT_SKIP;
249
+ if (cqe->res)
250
+ t_error(1, 0, "failed cqe %i", cqe->res);
251
+ break;
252
+ }
253
+
254
+ ts = (void *)(cqe + 1);
255
+ tstype = cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT;
256
+ tskey = cqe->res;
257
+ hwts = cqe->flags & IORING_CQE_F_TSTAMP_HW;
258
+
259
+ ts_got++;
260
+ if (verbose)
261
+ fprintf(stderr, "ts: key %x, type %i (%s), is hw %i, sec %lu, nsec %lu\n",
262
+ tskey, tstype, get_tstype_name(tstype), hwts,
263
+ (unsigned long)ts->tv_sec,
264
+ (unsigned long)ts->tv_nsec);
265
+
266
+ ret = validate_key(tskey, tstype, ctx);
267
+ if (ret)
268
+ return T_EXIT_FAIL;
269
+ }
270
+
271
+ if (ts_got != ts_expected) {
272
+ fprintf(stderr, "expected %i timestamps, got %i\n",
273
+ ts_expected, ts_got);
274
+ return -EINVAL;
275
+ }
276
+
277
+ close(fd);
278
+ io_uring_cq_advance(&ring, cqes_seen);
279
+ io_uring_queue_exit(&ring);
280
+ return T_EXIT_PASS;
281
+ }
282
+
283
+ static void resolve_hostname(const char *name, int port)
284
+ {
285
+ memset(&daddr6, 0, sizeof(daddr6));
286
+ daddr6.sin6_family = AF_INET6;
287
+ daddr6.sin6_port = htons(port);
288
+ if (inet_pton(AF_INET6, name, &daddr6.sin6_addr) != 1)
289
+ t_error(1, 0, "ipv6 parse error: %s", name);
290
+ }
291
+
292
+ static void do_listen(int family, int type, void *addr, int alen)
293
+ {
294
+ int fd;
295
+
296
+ fd = socket(family, type, 0);
297
+ if (fd == -1)
298
+ error(1, errno, "socket rx");
299
+
300
+ if (bind(fd, addr, alen))
301
+ error(1, errno, "bind rx");
302
+
303
+ if (type == SOCK_STREAM && listen(fd, 10))
304
+ error(1, errno, "listen rx");
305
+
306
+ /* leave fd open, will be closed on process exit.
307
+ * this enables connect() to succeed and avoids icmp replies
308
+ */
309
+ }
310
+
311
+ static int do_main(int family, int proto)
312
+ {
313
+ struct ctx ctx;
314
+ int ret;
315
+
316
+ ctx.num_pkts = 1;
317
+ ctx.family = family;
318
+ ctx.proto = proto;
319
+
320
+ if (verbose)
321
+ fprintf(stderr, "test SND\n");
322
+ ctx.report_opt = SOF_TIMESTAMPING_TX_SOFTWARE;
323
+ ret = do_test(&ctx);
324
+ if (ret) {
325
+ if (ret == T_EXIT_SKIP)
326
+ fprintf(stderr, "no timestamp cmd, skip\n");
327
+ return ret;
328
+ }
329
+
330
+ if (verbose)
331
+ fprintf(stderr, "test ENQ\n");
332
+ ctx.report_opt = SOF_TIMESTAMPING_TX_SCHED;
333
+ ret = do_test(&ctx);
334
+ if (ret)
335
+ return T_EXIT_FAIL;
336
+
337
+ if (verbose)
338
+ fprintf(stderr, "test ENQ + SND\n");
339
+ ctx.report_opt = SOF_TIMESTAMPING_TX_SCHED | SOF_TIMESTAMPING_TX_SOFTWARE;
340
+ ret = do_test(&ctx);
341
+ if (ret)
342
+ return T_EXIT_FAIL;
343
+
344
+ if (proto == SOCK_STREAM) {
345
+ if (verbose)
346
+ fprintf(stderr, "test ACK\n");
347
+ ctx.report_opt = SOF_TIMESTAMPING_TX_ACK;
348
+ ret = do_test(&ctx);
349
+ if (ret)
350
+ return T_EXIT_FAIL;
351
+
352
+ if (verbose)
353
+ fprintf(stderr, "test SND + ACK\n");
354
+ ctx.report_opt = SOF_TIMESTAMPING_TX_SOFTWARE |
355
+ SOF_TIMESTAMPING_TX_ACK;
356
+ ret = do_test(&ctx);
357
+ if (ret)
358
+ return T_EXIT_FAIL;
359
+
360
+ if (verbose)
361
+ fprintf(stderr, "test ENQ + SND + ACK\n");
362
+ ctx.report_opt = SOF_TIMESTAMPING_TX_SCHED |
363
+ SOF_TIMESTAMPING_TX_SOFTWARE |
364
+ SOF_TIMESTAMPING_TX_ACK;
365
+ ret = do_test(&ctx);
366
+ if (ret)
367
+ return T_EXIT_FAIL;
368
+ }
369
+ return 0;
370
+ }
371
+
372
+ int main(int argc, char **argv)
373
+ {
374
+ const char *hostname = "::1";
375
+
376
+ if (argc > 1)
377
+ return T_EXIT_SKIP;
378
+
379
+ resolve_hostname(hostname, dest_port);
380
+ do_listen(PF_INET6, SOCK_STREAM, &daddr6, sizeof(daddr6));
381
+ return do_main(PF_INET6, SOCK_STREAM);
382
+ }
@@ -43,7 +43,7 @@ static char str[] = "iv5t4dl500w7wsrf14fsuq8thptto0z7i2q62z1p8dwrv5u4kaxpqhm2rb7
43
43
  static int probe_zcrx(void *area)
44
44
  {
45
45
  struct io_uring_zcrx_area_reg area_reg = {
46
- .addr = (__u64)(unsigned long)area,
46
+ .addr = uring_ptr_to_u64(area),
47
47
  .len = AREA_SZ,
48
48
  .flags = 0,
49
49
  };
@@ -51,7 +51,7 @@ static int probe_zcrx(void *area)
51
51
  .if_idx = ifidx,
52
52
  .if_rxq = rxq,
53
53
  .rq_entries = RQ_ENTRIES,
54
- .area_ptr = (__u64)(unsigned long)&area_reg,
54
+ .area_ptr = uring_ptr_to_u64(&area_reg),
55
55
  };
56
56
  struct io_uring ring;
57
57
  int ret;
@@ -99,7 +99,7 @@ static int test_invalid_if(void *area)
99
99
  {
100
100
  int ret;
101
101
  struct io_uring_zcrx_area_reg area_reg = {
102
- .addr = (__u64)(unsigned long)area,
102
+ .addr = uring_ptr_to_u64(area),
103
103
  .len = AREA_SZ,
104
104
  .flags = 0,
105
105
  };
@@ -107,7 +107,7 @@ static int test_invalid_if(void *area)
107
107
  .if_idx = -1,
108
108
  .if_rxq = rxq,
109
109
  .rq_entries = RQ_ENTRIES,
110
- .area_ptr = (__u64)(unsigned long)&area_reg,
110
+ .area_ptr = uring_ptr_to_u64(&area_reg),
111
111
  };
112
112
 
113
113
  ret = try_register_ifq(&reg);
@@ -131,7 +131,7 @@ static int test_invalid_ifq_collision(void *area)
131
131
  {
132
132
  struct io_uring ring, ring2;
133
133
  struct io_uring_zcrx_area_reg area_reg = {
134
- .addr = (__u64)(unsigned long)area,
134
+ .addr = uring_ptr_to_u64(area),
135
135
  .len = AREA_SZ,
136
136
  .flags = 0,
137
137
  };
@@ -139,7 +139,7 @@ static int test_invalid_ifq_collision(void *area)
139
139
  .if_idx = ifidx,
140
140
  .if_rxq = rxq,
141
141
  .rq_entries = RQ_ENTRIES,
142
- .area_ptr = (__u64)(unsigned long)&area_reg,
142
+ .area_ptr = uring_ptr_to_u64(&area_reg),
143
143
  };
144
144
  int ret;
145
145
 
@@ -182,7 +182,7 @@ static int test_rq_setup(void *area)
182
182
  {
183
183
  int ret;
184
184
  struct io_uring_zcrx_area_reg area_reg = {
185
- .addr = (__u64)(unsigned long)area,
185
+ .addr = uring_ptr_to_u64(area),
186
186
  .len = AREA_SZ,
187
187
  .flags = 0,
188
188
  };
@@ -191,7 +191,7 @@ static int test_rq_setup(void *area)
191
191
  .if_idx = ifidx,
192
192
  .if_rxq = rxq,
193
193
  .rq_entries = 0,
194
- .area_ptr = (__u64)(unsigned long)&area_reg,
194
+ .area_ptr = uring_ptr_to_u64(&area_reg),
195
195
  };
196
196
 
197
197
  ret = try_register_ifq(&reg);
@@ -232,7 +232,7 @@ static int test_null_area_reg_struct(void)
232
232
  .if_idx = ifidx,
233
233
  .if_rxq = rxq,
234
234
  .rq_entries = RQ_ENTRIES,
235
- .area_ptr = (__u64)(unsigned long)0,
235
+ .area_ptr = uring_ptr_to_u64(0),
236
236
  };
237
237
 
238
238
  ret = try_register_ifq(&reg);
@@ -244,7 +244,7 @@ static int test_null_area(void)
244
244
  int ret;
245
245
 
246
246
  struct io_uring_zcrx_area_reg area_reg = {
247
- .addr = (__u64)(unsigned long)0,
247
+ .addr = uring_ptr_to_u64(0),
248
248
  .len = AREA_SZ,
249
249
  .flags = 0,
250
250
  };
@@ -253,7 +253,7 @@ static int test_null_area(void)
253
253
  .if_idx = ifidx,
254
254
  .if_rxq = rxq,
255
255
  .rq_entries = RQ_ENTRIES,
256
- .area_ptr = (__u64)(unsigned long)&area_reg,
256
+ .area_ptr = uring_ptr_to_u64(&area_reg),
257
257
  };
258
258
 
259
259
  ret = try_register_ifq(&reg);
@@ -264,7 +264,7 @@ static int test_misaligned_area(void *area)
264
264
  {
265
265
  int ret;
266
266
  struct io_uring_zcrx_area_reg area_reg = {
267
- .addr = (__u64)(unsigned long)(area + 1),
267
+ .addr = uring_ptr_to_u64(area + 1),
268
268
  .len = AREA_SZ,
269
269
  .flags = 0,
270
270
  };
@@ -273,13 +273,13 @@ static int test_misaligned_area(void *area)
273
273
  .if_idx = ifidx,
274
274
  .if_rxq = rxq,
275
275
  .rq_entries = RQ_ENTRIES,
276
- .area_ptr = (__u64)(unsigned long)&area_reg,
276
+ .area_ptr = uring_ptr_to_u64(&area_reg),
277
277
  };
278
278
 
279
279
  if (!try_register_ifq(&reg))
280
280
  return T_EXIT_FAIL;
281
281
 
282
- area_reg.addr = (__u64)(unsigned long)area;
282
+ area_reg.addr = uring_ptr_to_u64(area);
283
283
  area_reg.len = AREA_SZ - 1;
284
284
  ret = try_register_ifq(&reg);
285
285
  return ret ? T_EXIT_PASS : T_EXIT_FAIL;
@@ -289,7 +289,7 @@ static int test_larger_than_alloc_area(void *area)
289
289
  {
290
290
  int ret;
291
291
  struct io_uring_zcrx_area_reg area_reg = {
292
- .addr = (__u64)(unsigned long)area,
292
+ .addr = uring_ptr_to_u64(area),
293
293
  .len = AREA_SZ + 4096,
294
294
  .flags = 0,
295
295
  };
@@ -298,7 +298,7 @@ static int test_larger_than_alloc_area(void *area)
298
298
  .if_idx = ifidx,
299
299
  .if_rxq = rxq,
300
300
  .rq_entries = RQ_ENTRIES,
301
- .area_ptr = (__u64)(unsigned long)&area_reg,
301
+ .area_ptr = uring_ptr_to_u64(&area_reg),
302
302
  };
303
303
 
304
304
  ret = try_register_ifq(&reg);
@@ -315,7 +315,7 @@ static int test_area_access(void)
315
315
  .if_idx = ifidx,
316
316
  .if_rxq = rxq,
317
317
  .rq_entries = RQ_ENTRIES,
318
- .area_ptr = (__u64)(unsigned long)&area_reg,
318
+ .area_ptr = uring_ptr_to_u64(&area_reg),
319
319
  };
320
320
  int i, ret;
321
321
  void *area;
@@ -331,7 +331,7 @@ static int test_area_access(void)
331
331
  return T_EXIT_FAIL;
332
332
  }
333
333
 
334
- area_reg.addr = (__u64)(unsigned long)area;
334
+ area_reg.addr = uring_ptr_to_u64(area);
335
335
 
336
336
  ret = try_register_ifq(&reg);
337
337
  if (ret != -EFAULT) {
@@ -348,7 +348,7 @@ static int test_area_access(void)
348
348
  static int create_ring_with_ifq(struct io_uring *ring, void *area, __u32 *id)
349
349
  {
350
350
  struct io_uring_zcrx_area_reg area_reg = {
351
- .addr = (__u64)(unsigned long)area,
351
+ .addr = uring_ptr_to_u64(area),
352
352
  .len = AREA_SZ,
353
353
  .flags = 0,
354
354
  };
@@ -356,7 +356,7 @@ static int create_ring_with_ifq(struct io_uring *ring, void *area, __u32 *id)
356
356
  .if_idx = ifidx,
357
357
  .if_rxq = rxq,
358
358
  .rq_entries = RQ_ENTRIES,
359
- .area_ptr = (__u64)(unsigned long)&area_reg,
359
+ .area_ptr = uring_ptr_to_u64(&area_reg),
360
360
  };
361
361
  int ret;
362
362
 
@@ -653,7 +653,7 @@ static void *recv_fn(void *data)
653
653
  struct io_uring ring;
654
654
  int ret, sock;
655
655
  struct io_uring_zcrx_area_reg area_reg = {
656
- .addr = (__u64)(unsigned long)rd->area,
656
+ .addr = uring_ptr_to_u64(rd->area),
657
657
  .len = AREA_SZ,
658
658
  .flags = 0,
659
659
  };
@@ -661,7 +661,7 @@ static void *recv_fn(void *data)
661
661
  .if_idx = ifidx,
662
662
  .if_rxq = rxq,
663
663
  .rq_entries = RQ_ENTRIES,
664
- .area_ptr = (__u64)(unsigned long)&area_reg,
664
+ .area_ptr = uring_ptr_to_u64(&area_reg),
665
665
  };
666
666
 
667
667
  p.flags = RING_FLAGS;