Debian Codegraph @

src/func_tests/test_re_conf.c

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