Debian Codegraph @

src/func_tests/test_assoc_abort.c

raw symbols SCIP
1 /* SCTP kernel Implementation
2 * (C) Copyright IBM Corp. 2001, 2003
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001 Intel Corp.
6 * Copyright (c) 2001 Nokia, Inc.
7 *
8 * The SCTP implementation is free software;
9 * you can redistribute it and/or modify it under the terms of
10 * the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * The SCTP implementation is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * ************************
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with GNU CC; see the file COPYING. If not, write to
22 * the Free Software Foundation, 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
24 *
25 * Please send any bug reports or fixes you make to the
26 * email address(es):
27 * lksctp developers <[email protected]>
28 *
29 * Or submit a bug report through the following website:
30 * https://github.com/sctp/lksctp-tools/
31 *
32 * Any bugs reported to us we will try to fix... any fixes shared will
33 * be incorporated into the next SCTP release.
34 *
35 * Written or modified by:
36 * Ardelle Fan <[email protected]>
37 * Sridhar Samudrala <[email protected]>
38 */
39
40 /* This is a functional test to verify the ungraceful abort of an
41 * association.
42 */
43
44 #include <stdio.h>
45 #include <unistd.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <sys/types.h>
49 #include <sys/socket.h>
50 #include <sys/uio.h>
51 #include <netinet/in.h>
52 #include <errno.h>
53 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
54 #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/
55
56 char *TCIDcxx . . $ TCID. = __FILE__;
57 int TST_TOTALcxx . . $ TST_TOTAL. = 1;
58 int TST_CNTcxx . . $ TST_CNT. = 0;
59
60 #define MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`! 10
61
62 int
63 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
64 {
65 int svr_sk, clt_sk[MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`!];
66 sockaddr_storage_tcxx . . $ sockaddr_storage_t# svr_loop, clt_loop[MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`!];
67 sctp_assoc_tcxx . . $ sctp_assoc_t# svr_associd[MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`!];
68 struct ioveccxx . . $ iovec# iov;
69 struct msghdrcxx . . $ msghdr# inmessage;
70 struct msghdrcxx . . $ msghdr# outmessage;
71 char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(sctp_cmsg_data_t))];
72 char outcmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(struct sctp_sndrcvinfo))];
73 struct cmsghdrcxx . . $ cmsghdr# *cmsg;
74 struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *sinfo;
75 struct ioveccxx . . $ iovec# out_iov;
76 int error;
77 uint32_tcxx . . $ uint32_t# ppid;
78 uint32_tcxx . . $ uint32_t# stream;
79 struct sctp_assoc_changecxx . . $ sctp_assoc_change# *sac;
80 char *big_buffer;
81 int i;
82 char *message = "hello, world!\n";
83 struct sctp_statuscxx . . $ sctp_status# status;
84 socklen_tcxx . . $ socklen_t# status_len;
85
86 /* Rather than fflush() throughout the code, set stdout to
87 * be unbuffered.
88 */
89 setvbufcxx . . $ setvbuf(4da3ba8c983f31bc).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, _IONBFcxx . . $ `<external>/232824719582829767/stdio.h:100:9`!, 0);
90
91 /* Create and bind the server socket. */
92 svr_sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
93 svr_loop.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
94 svr_loop.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`!;
95 svr_loop.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`!);
96 test_bindcxx . . $ test_bind(18e507052d945257).(svr_sk, &svr_loop.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(svr_loop));
97
98 /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
99 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(svr_sk);
100
101 /* Mark server socket as being able to accept new associations. */
102 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(svr_sk, 1);
103
104 /* Create and bind all the client sockets. */
105 for (i = 0; i < MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`!; i++) {
106 clt_sk[i] = test_socketcxx . . $ test_socket(2326284602b0bb2d).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, SOCK_SEQPACKETcxx . . $ `<external>/5956532346368192945/socket_type.h:38:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
107
108 clt_loop[i].v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
109 clt_loop[i].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`!;
110 clt_loop[i].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`! + i);
111 test_bindcxx . . $ test_bind(18e507052d945257).(clt_sk[i], &clt_loop[i].sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(clt_loop[i]));
112
113 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(clt_sk[i]);
114 }
115
116 /* Build up a msghdr structure we can use for all sending. */
117 outmessage.msg_namecxx . . $ msghdr#msg_name. = &svr_loop;
118 outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(svr_loop);
119 outmessage.msg_iovcxx . . $ msghdr#msg_iov. = &out_iov;
120 outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
121 outmessage.msg_controlcxx . . $ msghdr#msg_control. = outcmsg;
122 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(outcmsg);
123 outmessage.msg_flagscxx . . $ msghdr#msg_flags. = 0;
124 cmsg = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&outmessage);
125 cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
126 cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. = SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!;
127 cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(struct sctp_sndrcvinfo));
128 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len.;
129 sinfo = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg);
130 memsetcxx . . $ memset(d1de1e4fb215f1c6).(sinfo, 0x00, sizeof(struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo#));
131 ppid = randcxx . . $ rand(b126dc7c1de90089).(); /* Choose an arbitrary value. */
132 stream = 1;
133 sinfo->sinfo_ppidcxx . . $ sctp_sndrcvinfo#sinfo_ppid. = ppid;
134 sinfo->sinfo_streamcxx . . $ sctp_sndrcvinfo#sinfo_stream. = stream;
135 out_iov.iov_basecxx . . $ iovec#iov_base. = message;
136 out_iov.iov_lencxx . . $ iovec#iov_len. = strlencxx . . $ strlen(751346f8406fd082).(message) + 1;
137
138 /* Send the first message from all the clients to the server. This
139 * will create the associations.
140 */
141 for (i = 0; i < MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`!; i++)
142 test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(clt_sk[i], &outmessage, 0, strlencxx . . $ strlen(751346f8406fd082).(message) + 1);
143
144 /* Initialize inmessage for all receives. */
145 big_buffer = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!);
146 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
147 iov.iov_basecxx . . $ iovec#iov_base. = big_buffer;
148 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!;
149 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
150 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
151 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
152
153 /* Get the communication up message on all client sockets. */
154 for (i = 0; i < MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`!; i++) {
155 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
156 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(clt_sk[i], &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
157 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
158 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
159 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
160 }
161
162 /* Get the communication up message and the data message on the
163 * server sockets for all the clients.
164 */
165 for (i = 0; i < MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`!; i++) {
166 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
167 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(svr_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
168 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
169 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
170 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
171
172 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
173 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(svr_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
174 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, strlencxx . . $ strlen(751346f8406fd082).(message) + 1,
175 MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid);
176 sac = (struct sctp_assoc_changecxx . . $ sctp_assoc_change# *)iov.iov_basecxx . . $ iovec#iov_base.;
177 svr_associd[i] = sac->sac_assoc_idcxx . . $ sctp_assoc_change#sac_assoc_id.;
178 }
179
180 outmessage.msg_namecxx . . $ msghdr#msg_name. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
181 outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = 0;
182 outmessage.msg_iovcxx . . $ msghdr#msg_iov. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
183 outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 0;
184 outmessage.msg_controlcxx . . $ msghdr#msg_control. = outcmsg;
185 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(outcmsg);
186 outmessage.msg_flagscxx . . $ msghdr#msg_flags. = 0;
187 cmsg = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&outmessage);
188 cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
189 cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. = SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!;
190 cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(struct sctp_sndrcvinfo));
191 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len.;
192 sinfo = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg);
193 memsetcxx . . $ memset(d1de1e4fb215f1c6).(sinfo, 0x00, sizeof(struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo#));
194 sinfo->sinfo_flagscxx . . $ sctp_sndrcvinfo#sinfo_flags. |= SCTP_ABORTcxx . . $ SCTP_ABORT.;
195
196 /* Shutdown all the associations of the server socket in a loop. */
197 for (i = 0; i < MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`!; i++) {
198 sinfo->sinfo_assoc_idcxx . . $ sctp_sndrcvinfo#sinfo_assoc_id. = svr_associd[i];
199
200 /* Verify that the association is present. */
201 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&status, 0, sizeof(struct sctp_statuscxx . . $ sctp_status#));
202 status.sstat_assoc_idcxx . . $ sctp_status#sstat_assoc_id. = sinfo->sinfo_assoc_idcxx . . $ sctp_sndrcvinfo#sinfo_assoc_id.;
203 status_len = sizeof(struct sctp_statuscxx . . $ sctp_status#);
204 error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(svr_sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_STATUScxx . . $ `<external>/17169092326581286071/sctp.h:83:9`!,
205 &status, &status_len);
206 if (error)
207 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit,
208 "getsockopt(SCTP_STATUS): %s",
209 strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
210
211 /* Call sendmsg() to abort the association. */
212 test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(svr_sk, &outmessage, 0, 0);
213
214 /* Verify that the association is no longer present. */
215 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&status, 0, sizeof(struct sctp_statuscxx . . $ sctp_status#));
216 status.sstat_assoc_idcxx . . $ sctp_status#sstat_assoc_id. = sinfo->sinfo_assoc_idcxx . . $ sctp_sndrcvinfo#sinfo_assoc_id.;
217 status_len = sizeof(struct sctp_statuscxx . . $ sctp_status#);
218 error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(svr_sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_STATUScxx . . $ `<external>/17169092326581286071/sctp.h:83:9`!,
219 &status, &status_len);
220 if ((error != -1) && (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!))
221 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit,
222 "getsockopt(SCTP_STATUS) "
223 "error:%d errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
224 }
225
226 closecxx . . $ close(7864480464b09eea).(svr_sk);
227
228 /* Get the COMM_LOST notification. */
229 for (i = 0; i < MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_abort.c:60:9`!; i++) {
230 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
231 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(clt_sk[i], &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
232 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
233 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#)+4,
234 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_LOSTcxx . . $ SCTP_COMM_LOST.);
235
236 closecxx . . $ close(7864480464b09eea).(clt_sk[i]);
237 }
238
239 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "ABORT an association using SCTP_ABORT");
240
241 freecxx . . $ free(5d22bdacc48458e8).(big_buffer);
242 /* Indicate successful completion. */
243 return 0;
244 }