Debian Codegraph @

src/func_tests/test_connect.c

raw symbols SCIP
1 /* SCTP kernel Implementation
2 * (C) Copyright IBM Corp. 2002, 2003
3 * Copyright (c) 1999-2001 Motorola, Inc.
4 *
5 * The SCTP implementation is free software;
6 * you can redistribute it and/or modify it under the terms of
7 * the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * The SCTP implementation is distributed in the hope that it
12 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
13 * ************************
14 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU CC; see the file COPYING. If not, write to
19 * the Free Software Foundation, 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 *
22 * Please send any bug reports or fixes you make to the
23 * email address(es):
24 * lksctp developers <[email protected]>
25 *
26 * Or submit a bug report through the following website:
27 * https://github.com/sctp/lksctp-tools/
28 *
29 * Any bugs reported given to us we will try to fix... any fixes shared will
30 * be incorporated into the next SCTP release.
31 *
32 * Written or modified by:
33 * Sridhar Samudrala <[email protected]>
34 */
35
36 /* This is a kernel test to verify the one-to-many style connect() in blocking
37 * and non-blocking modes.
38 */
39
40 #include <stdio.h>
41 #include <unistd.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <fcntl.h>
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <sys/uio.h>
48 #include <netinet/in.h>
49 #include <errno.h>
50 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
51 #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/
52
53 char *TCIDcxx . . $ TCID. = __FILE__;
54 int TST_TOTALcxx . . $ TST_TOTAL. = 5;
55 int TST_CNTcxx . . $ TST_CNT. = 0;
56
57 int
58 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
59 {
60 int svr_sk, clt_sk1, clt_sk2, peeloff_sk;
61 sctp_assoc_tcxx . . $ sctp_assoc_t# svr_associd1;
62 sockaddr_storage_tcxx . . $ sockaddr_storage_t# svr_loop, clt_loop1, clt_loop2, clt_loop3;
63 struct sctp_assoc_changecxx . . $ sctp_assoc_change# *sac;
64 struct ioveccxx . . $ iovec# iov;
65 struct msghdrcxx . . $ msghdr# inmessage;
66 int error;
67 char *big_buffer;
68 int flags;
69
70 /* Rather than fflush() throughout the code, set stdout to
71 * be unbuffered.
72 */
73 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);
74
75 /* Initialize the server and client addresses. */
76 svr_loop.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
77 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`!;
78 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`!);
79 clt_loop1.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
80 clt_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`!;
81 clt_loop1.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`!);
82 clt_loop2.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
83 clt_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`!;
84 clt_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`!+1);
85 clt_loop3.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
86 clt_loop3.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 clt_loop3.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`!+2);
88
89 /* Create and bind the server socket. */
90 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`!);
91 test_bindcxx . . $ test_bind(18e507052d945257).(svr_sk, &svr_loop.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(svr_loop));
92
93 /* Mark server socket as being able to accept new associations. */
94 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(svr_sk, 1);
95
96 /* Create and bind the client sockets. */
97 clt_sk1 = 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`!);
98 test_bindcxx . . $ test_bind(18e507052d945257).(clt_sk1, &clt_loop1.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(clt_loop1));
99 clt_sk2 = 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`!);
100 test_bindcxx . . $ test_bind(18e507052d945257).(clt_sk2, &clt_loop2.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(clt_loop2));
101
102 /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
103 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(svr_sk);
104 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(clt_sk1);
105 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(clt_sk2);
106
107 /* Set clt_sk1 as non-blocking. */
108 flags = fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(clt_sk1, F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!, 0);
109 if (flags < 0)
110 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "fcntl F_GETFL: %s", strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
111 if (fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(clt_sk1, F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, flags | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!) < 0)
112 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "fcntl F_SETFL: %s", strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
113
114 /* Do a non-blocking connect from clt_sk1 to svr_sk */
115 error = connectcxx . . $ connect(1ce9971e209c3c95).(clt_sk1, &svr_loop.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(svr_loop));
116 /* Non-blocking connect should return immediately with EINPROGRESS. */
117 if ((error != -1) || (EINPROGRESScxx . . $ `<external>/17922322188510340118/errno.h:99:9`! != errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!))
118 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "non-blocking connect error: %d"
119 "errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
120
121 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "non-blocking connect");
122
123 /* Doing a connect on a socket to create an association that is
124 * is already established should return EISCONN.
125 */
126 error = connectcxx . . $ connect(1ce9971e209c3c95).(clt_sk1, &svr_loop.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(svr_loop));
127 if ((error != -1) || (EISCONNcxx . . $ `<external>/17922322188510340118/errno.h:90:9`! != errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!))
128 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "connect on a socket to create an "
129 "assoc that is already established error:%d errno:%d",
130 error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
131
132 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "connect on a socket to create an assoc that is "
133 "already established");
134
135 /* Initialize inmessage for all receives. */
136 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
137 big_buffer = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!);
138 iov.iov_basecxx . . $ iovec#iov_base. = big_buffer;
139 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!;
140 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
141 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
142 inmessage.msg_controlcxx . . $ msghdr#msg_control. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
143
144 /* Get COMM_UP on clt_sk1 */
145 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(clt_sk1, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
146 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
147 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
148 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
149 #if 0
150 sac = (struct sctp_assoc_change *)iov.iov_base;
151 clt_associd1 = sac->sac_assoc_id;
152 #endif
153
154 /* Get COMM_UP on svr_sk */
155 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(svr_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
156 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
157 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
158 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
159 sac = (struct sctp_assoc_changecxx . . $ sctp_assoc_change# *)iov.iov_basecxx . . $ iovec#iov_base.;
160 svr_associd1 = sac->sac_assoc_idcxx . . $ sctp_assoc_change#sac_assoc_id.;
161
162 /* Do a blocking connect from clt_sk2 to svr_sk.
163 * Blocking connect should block until the association is established
164 * and return success.
165 */
166 test_connectcxx . . $ test_connect(18e507052d945257).(clt_sk2, &svr_loop.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(svr_loop));
167
168 /* Get COMM_UP on clt_sk2 */
169 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(clt_sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
170 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
171 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
172 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
173 #if 0
174 sac = (struct sctp_assoc_change *)iov.iov_base;
175 clt_associd2 = sac->sac_assoc_id;
176 #endif
177
178 /* Get COMM_UP on svr_sk */
179 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(svr_sk, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
180 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
181 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
182 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
183 #if 0
184 sac = (struct sctp_assoc_change *)iov.iov_base;
185 svr_associd2 = sac->sac_assoc_id;
186 #endif
187
188 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "blocking connect");
189
190 peeloff_sk = test_sctp_peeloffcxx . . $ test_sctp_peeloff(9b79fb6aee4c0440).(svr_sk, svr_associd1);
191
192 /* Doing a connect on a peeled off socket should fail. */
193 error = connectcxx . . $ connect(1ce9971e209c3c95).(peeloff_sk, &clt_loop3.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(clt_loop3));
194 if ((error != -1) || (EISCONNcxx . . $ `<external>/17922322188510340118/errno.h:90:9`! != errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!))
195 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "connect on a peeled off socket "
196 "error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
197
198 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "connect on a peeled off socket");
199
200 /* Trying to create an association on a socket that matches an
201 * existing peeled-off association should fail.
202 */
203 error = connectcxx . . $ connect(1ce9971e209c3c95).(svr_sk, &clt_loop1.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(clt_loop1));
204 if ((error != -1) || (EADDRNOTAVAILcxx . . $ `<external>/17922322188510340118/errno.h:83:9`! != errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!))
205 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "connect to create an assoc that "
206 "matches a peeled off assoc error:%d errno:%d",
207 error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
208
209 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "connect to create an assoc that matches a peeled off "
210 "assoc");
211
212 closecxx . . $ close(7864480464b09eea).(svr_sk);
213 closecxx . . $ close(7864480464b09eea).(clt_sk1);
214 closecxx . . $ close(7864480464b09eea).(clt_sk2);
215 closecxx . . $ close(7864480464b09eea).(peeloff_sk);
216
217 freecxx . . $ free(5d22bdacc48458e8).(big_buffer);
218 /* Indicate successful completion. */
219 return 0;
220 }