Debian Codegraph @

src/func_tests/test_interleave.c

raw symbols SCIP
1 /* This purpose of this test is to examine the
2 * support of the interleaving
3 * The following tests are done in sequence:
4 * - Verify SCTP_FRAGMENT_INTERLEAVE and SCTP_INTERLEAVING_SUPPORTED
5 * socket option by doing a setsockopt() followed by a getsockopt()
6 * - Verify the integrity of the data sent by client using a sendmsg()
7 */
8
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <sys/uio.h>
16 #include <netinet/in.h>
17 #include <errno.h>
18 #include <fcntl.h>
19 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
20 #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/
21
22 #define MSG_SIZEcxx . . $ `src/func_tests/test_interleave.c:22:9`! 1000
23
24 char *TCIDcxx . . $ TCID. = __FILE__;
25 int TST_TOTALcxx . . $ TST_TOTAL. = 2;
26 int TST_CNTcxx . . $ TST_CNT. = 0;
27
28 int
29 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
30 {
31 int sk1, sk2;
32 int pf_class;
33 int error;
34 int fd;
35 int msg_len, bytes_sent;
36 int frag_interleave, get_result;
37 sockaddr_storage_tcxx . . $ sockaddr_storage_t# loop1;
38 sockaddr_storage_tcxx . . $ sockaddr_storage_t# loop2;
39 struct ioveccxx . . $ iovec# iov;
40 struct ioveccxx . . $ iovec# out_iov;
41 struct msghdrcxx . . $ msghdr# inmessage;
42 struct msghdrcxx . . $ msghdr# outmessage;
43 struct cmsghdrcxx . . $ cmsghdr# *cmsg;
44 struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *sinfo;
45 struct sctp_assoc_valuecxx . . $ sctp_assoc_value# assoc, get_assoc;
46 uint32_tcxx . . $ uint32_t# ppid;
47 uint32_tcxx . . $ uint32_t# stream;
48 char *buffer;
49 char setting[4];
50 char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(sctp_cmsg_data_t))];
51 char outcmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(struct sctp_sndrcvinfo))];
52 void *msg_buffer;
53 socklen_tcxx . . $ socklen_t# optlen;
54
55 /* Rather than fflush() throughout the code, set stdout to
56 * be unbuffered.
57 */
58 setvbufcxx . . $ setvbuf(4da3ba8c983f31bc).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, _IONBFcxx . . $ `<external>/232824719582829767/stdio.h:100:9`!, 0);
59
60 /* Set some basic values which depend on the address family. */
61 #if TEST_V6
62 pf_class = PF_INET6;
63
64 loop1.v6.sin6_family = AF_INET6;
65 loop1.v6.sin6_addr = in6addr_loopbackcxx . . $ in6addr_loopback.;
66 loop1.v6.sin6_port = htons(SCTP_TESTPORT_1);
67
68 loop2.v6.sin6_family = AF_INET6;
69 loop2.v6.sin6_addr = in6addr_loopbackcxx . . $ in6addr_loopback.;
70 loop2.v6.sin6_port = htons(SCTP_TESTPORT_2);
71 #else
72 pf_class = PF_INETcxx . . $ `<external>/8962547315054503424/socket.h:45:9`!;
73
74 loop1.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
75 loop1.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
76 loop1.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_1cxx . . $ `src/testlib/sctputil.h:71:9`!);
77
78 loop2.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
79 loop2.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
80 loop2.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_2cxx . . $ `src/testlib/sctputil.h:73:9`!);
81 #endif /* TEST_V6 */
82
83 /* Create the two endpoints which will talk to each other */
84 sk1 = test_socketcxx . . $ test_socket(2326284602b0bb2d).(pf_class, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
85 sk2 = test_socketcxx . . $ test_socket(2326284602b0bb2d).(pf_class, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
86
87 /* Enable ASSOC_CHANGE and SNDRCVINFO notifications */
88 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(sk1);
89 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(sk2);
90
91 /* Bind these sockets to the test ports */
92 test_bindcxx . . $ test_bind(18e507052d945257).(sk1, &loop1.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(loop1));
93 test_bindcxx . . $ test_bind(18e507052d945257).(sk2, &loop2.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(loop2));
94
95 /* Let sk2 listen to new associations */
96 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(sk2, 1);
97
98 /* TEST #1: verify SCTP_FRAGMENT_INTERLEAVE option
99 * followed by a getsockopt()
100 */
101 frag_interleave = 1;
102 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(sk1, SCTP_FRAGMENT_INTERLEAVEcxx . . $ `<external>/17169092326581286071/sctp.h:89:9`!,
103 &frag_interleave, sizeof(frag_interleave));
104 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(sk2, SCTP_FRAGMENT_INTERLEAVEcxx . . $ `<external>/17169092326581286071/sctp.h:89:9`!,
105 &frag_interleave, sizeof(frag_interleave));
106
107 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "setsockopt(SCTP_FRAGMENT_INTERLEAVE)");
108
109 get_result = 0;
110 optlen = sizeof(get_result);
111 error = test_getsockoptcxx . . $ test_getsockopt(55626bc83d624bdb).(sk1, SCTP_FRAGMENT_INTERLEAVEcxx . . $ `<external>/17169092326581286071/sctp.h:89:9`!,
112 &get_result, &optlen);
113 if (get_result != frag_interleave)
114 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "getsockopt(SCTP_FRAGMENT_INTERLEAVE) "
115 "error: %d errno: %d get_result: %d",
116 error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, get_result);
117 get_result = 0;
118 error = test_getsockoptcxx . . $ test_getsockopt(55626bc83d624bdb).(sk2, SCTP_FRAGMENT_INTERLEAVEcxx . . $ `<external>/17169092326581286071/sctp.h:89:9`!,
119 &get_result, &optlen);
120 if (get_result != frag_interleave)
121 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "getsockopt(SCTP_FRAGMENT_INTERLEAVE) "
122 "error: %d errno: %d get_result: %d",
123 error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, get_result);
124
125 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "getsockopt(SCTP_FRAGMENT_INTERLEAVE)");
126
127 /* Check if net.sctp.intl_enable=1, exit if not */
128 fd = opencxx . . $ open(e156e3aa1e5c4ad1).("/proc/sys/net/sctp/intl_enable", O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!);
129 if (fd < 0 ||
130 readcxx . . $ read(7e34d0a36f355389).(fd, &setting, 4) < 0 ||
131 strncmpcxx . . $ strncmp(fd278af2f295fa2e).("1", setting, 1) != 0) {
132 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TINFO, "intl_enable is not set to 1, skip test\n");
133 return 0;
134 }
135 closecxx . . $ close(7864480464b09eea).(fd);
136
137 assoc.assoc_idcxx . . $ sctp_assoc_value#assoc_id. = 0;
138 assoc.assoc_valuecxx . . $ sctp_assoc_value#assoc_value. = 1;
139 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(sk1, SCTP_INTERLEAVING_SUPPORTEDcxx . . $ `<external>/17169092326581286071/sctp.h:135:9`!,
140 &assoc, sizeof(assoc));
141 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(sk2, SCTP_INTERLEAVING_SUPPORTEDcxx . . $ `<external>/17169092326581286071/sctp.h:135:9`!,
142 &assoc, sizeof(assoc));
143
144 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "setsockopt(SCTP_INTERLEAVING_SUPPORTED)");
145
146
147 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&get_assoc, 0x00, sizeof(struct sctp_assoc_valuecxx . . $ sctp_assoc_value#));
148 optlen = sizeof(get_assoc);
149 error = test_getsockoptcxx . . $ test_getsockopt(55626bc83d624bdb).(sk1, SCTP_INTERLEAVING_SUPPORTEDcxx . . $ `<external>/17169092326581286071/sctp.h:135:9`!,
150 &get_assoc, &optlen);
151 if (get_assoc.assoc_valuecxx . . $ sctp_assoc_value#assoc_value. != 1)
152 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit,
153 "getsockopt(SCTP_INTERLEAVING_SUPPORTED) "
154 "error: %d errno: %d get_result: %d",
155 error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, get_assoc.assoc_value);
156 error = test_getsockoptcxx . . $ test_getsockopt(55626bc83d624bdb).(sk2, SCTP_INTERLEAVING_SUPPORTEDcxx . . $ `<external>/17169092326581286071/sctp.h:135:9`!,
157 &get_assoc, &optlen);
158 if (get_assoc.assoc_valuecxx . . $ sctp_assoc_value#assoc_value. != 1)
159 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit,
160 "getsockopt(SCTP_INTERLEAVING_SUPPORTED) "
161 "error: %d errno: %d get_result: %d",
162 error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, get_assoc.assoc_value);
163
164 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "getsockopt(SCTP_INTERLEAVING_SUPPORTED)");
165 /* End of TEST #1 */
166
167 /* Send the first message to create an association */
168 outmessage.msg_namecxx . . $ msghdr#msg_name. = &loop2;
169 outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(loop2);
170 outmessage.msg_iovcxx . . $ msghdr#msg_iov. = &out_iov;
171 outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
172 outmessage.msg_controlcxx . . $ msghdr#msg_control. = outcmsg;
173 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(outcmsg);
174 outmessage.msg_flagscxx . . $ msghdr#msg_flags. = 0;
175 cmsg = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&outmessage);
176 cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
177 cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. = SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!;
178 cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(struct sctp_sndrcvinfo));
179 sinfo = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg);
180 memsetcxx . . $ memset(d1de1e4fb215f1c6).(sinfo, 0x00, sizeof(struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo#));
181 ppid = randcxx . . $ rand(b126dc7c1de90089).(); /* Choose an arbitrary value */
182 stream = 1;
183 sinfo->sinfo_ppidcxx . . $ sctp_sndrcvinfo#sinfo_ppid. = ppid;
184 sinfo->sinfo_streamcxx . . $ sctp_sndrcvinfo#sinfo_stream. = stream;
185 msg_len = 10;
186 msg_buffer = test_build_msgcxx . . $ test_build_msg(d1680a912d714170).(10);
187 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = msg_buffer;
188 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = msg_len;
189 test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(sk1, &outmessage, 0, msg_len);
190
191 /* Initialize inmessage for all receives */
192 buffer = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!);
193 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0x00, sizeof(inmessage));
194 iov.iov_basecxx . . $ iovec#iov_base. = buffer;
195 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!;
196 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
197 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
198 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
199
200 /* Get the communication up message on sk2 */
201 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
202 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
203 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
204 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
205 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
206
207 /* Get the communication up message on sk1 */
208 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
209 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk1, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
210 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
211 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
212 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
213
214 /* Get the first message which was sent. */
215 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
216 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
217 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, msg_len, MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid);
218 freecxx . . $ free(5d22bdacc48458e8).(msg_buffer);
219
220 /* TEST #2: Verify data integrity */
221 msg_len = MSG_SIZEcxx . . $ `src/func_tests/test_interleave.c:22:9`!;
222 msg_buffer = test_build_msgcxx . . $ test_build_msg(d1680a912d714170).(msg_len);
223 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = msg_buffer;
224 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = msg_len;
225 bytes_sent = test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(sk1, &outmessage, 0, msg_len);
226
227 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TINFO, "Sent %d byte message", bytes_sent);
228
229 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
230 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
231
232 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TINFO, "Received %d byte message", error);
233
234 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, bytes_sent,
235 MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid);
236
237 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "Received same byte of message");
238 /* End of TEST #2 */
239
240 /* Shut down the link */
241 closecxx . . $ close(7864480464b09eea).(sk1);
242
243 /* Get the shutdown complete notification */
244 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
245 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
246 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
247 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
248 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.);
249 closecxx . . $ close(7864480464b09eea).(sk2);
250
251 freecxx . . $ free(5d22bdacc48458e8).(buffer);
252 freecxx . . $ free(5d22bdacc48458e8).(msg_buffer);
253 /* Indicate successful completion */
254 return 0;
255 }