Debian Codegraph @

src/func_tests/test_1_to_1_connectx.c

raw symbols SCIP
1 /* SCTP kernel Implementation
2 * Copyright (c) 2003 Hewlett-Packard Development Company, L.P
3 * (C) Copyright IBM Corp. 2004
4 *
5 * This file has test cases to test the sctp_connectx () call for 1-1 style sockets
6 *
7 * TEST1: Bad socket descriptor
8 * TEST2: Invalid socket
9 * TEST3: Invalid address
10 * TEST4: Invalid address length
11 * TEST5: Invalid address family
12 * TEST6: Valid blocking sctp_connectx
13 * TEST7: Connect when accept queue is full
14 * TEST8: On a listening socket
15 * TEST9: On established socket
16 * TEST10: Connect to re-establish a closed association.
17 *
18 * The SCTP implementation is free software;
19 * you can redistribute it and/or modify it under the terms of
20 * the GNU General Public License as published by
21 * the Free Software Foundation; either version 2, or (at your option)
22 * any later version.
23 *
24 * The SCTP implementation is distributed in the hope that it
25 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
26 * ************************
27 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 * See the GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with GNU CC; see the file COPYING. If not, write to
32 * the Free Software Foundation, 59 Temple Place - Suite 330,
33 * Boston, MA 02111-1307, USA.
34 *
35 * Please send any bug reports or fixes you make to the
36 * email address(es):
37 * lksctp developers <[email protected]>
38 *
39 * Or submit a bug report through the following website:
40 * https://github.com/sctp/lksctp-tools/
41 *
42 * Any bugs reported given to us we will try to fix... any fixes shared will
43 * be incorporated into the next SCTP release
44 *
45 */
46
47 #include <stdio.h>
48 #include <unistd.h>
49 #include <fcntl.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <sys/types.h>
53 #include <sys/socket.h>
54 #include <linux/socket.h>
55 #include <netinet/in.h> /* for sockaddr_in */
56 #include <arpa/inet.h>
57 #include <errno.h>
58 #include <sys/uio.h>
59 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
60 #include "sctputil.h"cxx . . $ `<file>/src/testlib/sctputil.h`/
61
62 char *TCIDcxx . . $ TCID. = __FILE__;
63 int TST_TOTALcxx . . $ TST_TOTAL. = 10;
64 int TST_CNTcxx . . $ TST_CNT. = 0;
65
66 #define SK_MAXcxx . . $ `src/func_tests/test_1_to_1_connectx.c:66:9`! 10
67
68 int
69 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
70 {
71 int error,i;
72 socklen_tcxx . . $ socklen_t# len;
73 int sk,lstn_sk,clnt_sk[SK_MAXcxx . . $ `src/func_tests/test_1_to_1_connectx.c:66:9`!],acpt_sk[SK_MAXcxx . . $ `src/func_tests/test_1_to_1_connectx.c:66:9`!],pf_class;
74 int sk1,clnt2_sk;
75
76 struct sockaddr_incxx . . $ sockaddr_in# conn_addr,lstn_addr,acpt_addr;
77 struct sockaddrcxx . . $ sockaddr# *tmp_addr;
78
79 /* Rather than fflush() throughout the code, set stdout to
80 * be unbuffered.
81 */
82 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);
83 setvbufcxx . . $ setvbuf(4da3ba8c983f31bc).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, _IONBFcxx . . $ `<external>/232824719582829767/stdio.h:100:9`!, 0);
84
85 pf_class = PF_INETcxx . . $ `<external>/8962547315054503424/socket.h:45:9`!;
86
87 sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(pf_class, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
88 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`!);
89
90 /*Creating a listen socket*/
91 lstn_sk = 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
93 /*Creating a regular socket*/
94 for (i = 0 ; i < SK_MAXcxx . . $ `src/func_tests/test_1_to_1_connectx.c:66:9`! ; i++)
95 clnt_sk[i] = test_socketcxx . . $ test_socket(2326284602b0bb2d).(pf_class, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
96
97 clnt2_sk = test_socketcxx . . $ test_socket(2326284602b0bb2d).(pf_class, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!);
98
99 conn_addr.sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
100 conn_addr.sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
101 conn_addr.sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_1cxx . . $ `src/testlib/sctputil.h:71:9`!);
102
103 lstn_addr.sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
104 lstn_addr.sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = SCTP_IP_LOOPBACKcxx . . $ `src/testlib/sctputil.h:76:9`!;
105 lstn_addr.sin_portcxx . . $ sockaddr_in#sin_port. = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(SCTP_TESTPORT_1cxx . . $ `src/testlib/sctputil.h:71:9`!);
106
107 /*Binding the listen socket*/
108 test_bindcxx . . $ test_bind(18e507052d945257).(lstn_sk, (struct sockaddrcxx . . $ sockaddr# *) &lstn_addr, sizeof(lstn_addr));
109
110 /*Listening the socket*/
111 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(lstn_sk, SK_MAXcxx . . $ `src/func_tests/test_1_to_1_connectx.c:66:9`!-1);
112
113
114 /*sctp_connectx () TEST1: Bad socket descriptor, EBADF Expected error*/
115 len = sizeof(struct sockaddr_incxx . . $ sockaddr_in#);
116 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(-1, (struct sockaddrcxx . . $ sockaddr# *) &conn_addr, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
117 if (error != -1 || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EBADFcxx . . $ `<external>/8987895939074593727/errno-base.h:13:9`!)
118 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sctp_connectx with bad socket "
119 "descriptor error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
120
121 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sctp_connectx() with bad socket descriptor - EBADF");
122
123 /*sctp_connectx () TEST2: Invalid socket, ENOTSOCK Expected error*/
124 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(0, (struct sockaddrcxx . . $ sockaddr# *) &conn_addr, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
125 if (error != -1 || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != ENOTSOCKcxx . . $ `<external>/17922322188510340118/errno.h:72:9`!)
126 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sctp_connectx with invalid socket "
127 "error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
128
129 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sctp_connectx() with invalid socket - ENOTSOCK");
130
131 /*sctp_connectx () TEST3: Invalid address, EINVAL Expected error*/
132 tmp_addr = (struct sockaddrcxx . . $ sockaddr# *)test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(sizeof(struct sockaddrcxx . . $ sockaddr#));
133 tmp_addr->sa_familycxx . . $ sockaddr#sa_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
134 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(sk, tmp_addr, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
135 if (error != -1 || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!)
136 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sctp_connectx with invalid address "
137 "error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
138
139 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sctp_connectx() with invalid address - EINVAL");
140
141 /*sctp_connectx () TEST4: Invalid address length, EINVAL Expected error*/
142 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(sk, (struct sockaddrcxx . . $ sockaddr# *) &conn_addr, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
143 if (error != -1 || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!)
144 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sctp_connectx with invalid address length "
145 "error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
146
147 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sctp_connectx() with invalid address length - EINVAL");
148
149 /*sctp_connectx () TEST5: Invalid address family, EINVAL Expect error*/
150 conn_addr.sin_familycxx . . $ sockaddr_in#sin_family. = 9090; /*Assigning invalid address family*/
151 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(sk, (struct sockaddrcxx . . $ sockaddr# *) &conn_addr, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
152 if (error != -1 || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!)
153 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sctp_connectx with invalid address family "
154 "error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
155
156 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sctp_connectx() with invalid address family - EINVAL");
157
158 conn_addr.sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
159
160 /*sctp_connectx () TEST6: Blocking sctp_connectx, should pass*/
161 /*All the be below blocking sctp_connectx should pass as socket will be
162 listening SK_MAX clients*/
163 for (i = 0 ; i < SK_MAXcxx . . $ `src/func_tests/test_1_to_1_connectx.c:66:9`! ; i++) {
164 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(clnt_sk[i], (struct sockaddrcxx . . $ sockaddr# *)&conn_addr,
165 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
166 if (error < 0)
167 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "valid blocking sctp_connectx "
168 "error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
169 }
170
171 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "valid blocking sctp_connectx() - SUCCESS");
172
173 /*sctp_connectx () TEST7: sctp_connectx when accept queue is full, ECONNREFUSED
174 Expect error*/
175 /*Now that accept queue is full, the below sctp_connectx should fail*/
176 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(clnt2_sk, (struct sockaddrcxx . . $ sockaddr# *) &conn_addr, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
177 if (error != -1 || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != ECONNREFUSEDcxx . . $ `<external>/17922322188510340118/errno.h:95:9`!)
178 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sctp_connectx when accept queue is full "
179 "error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
180
181 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sctp_connectx() when accept queue is full - ECONNREFUSED");
182
183 /*Calling a accept first to estblish the pending sctp_connectxions*/
184 for (i=0 ; i < SK_MAXcxx . . $ `src/func_tests/test_1_to_1_connectx.c:66:9`! ; i++)
185 acpt_sk[i] = test_acceptcxx . . $ test_accept(46fcd054f4a4d98b).(lstn_sk,
186 (struct sockaddrcxx . . $ sockaddr# *) &acpt_addr, &len);
187
188 /*sctp_connectx () TEST8: from a listening socket, EISCONN Expect error*/
189 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(lstn_sk, (struct sockaddrcxx . . $ sockaddr# *) &lstn_addr, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
190 if (error != -1 || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EISCONNcxx . . $ `<external>/17922322188510340118/errno.h:90:9`!)
191 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sctp_connectx on a listening socket "
192 "error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
193
194 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sctp_connectx() on a listening socket - EISCONN");
195
196 /*sctp_connectx() TEST9: On established socket, EISCONN Expect error*/
197 i=0;
198 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(acpt_sk[i], (struct sockaddrcxx . . $ sockaddr# *) &lstn_addr, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
199 if (error != -1 || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EISCONNcxx . . $ `<external>/17922322188510340118/errno.h:90:9`!)
200 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "sctp_connectx on an established socket "
201 "error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
202
203 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sctp_connectx() on an established socket - EISCONN");
204
205 for (i = 0 ; i < 4 ; i++) {
206 closecxx . . $ close(7864480464b09eea).(clnt_sk[i]);
207 closecxx . . $ close(7864480464b09eea).(acpt_sk[i]);
208 }
209
210 /* sctp_connectx() TEST10: Re-establish an association that is closed.
211 * should succeed.
212 */
213 error = sctp_connectxcxx . . $ sctp_connectx(c1090d8010e18ca3).(sk1, (struct sockaddrcxx . . $ sockaddr# *)&conn_addr, 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
214 if (error < 0)
215 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "Re-establish an association that "
216 "is closed error:%d, errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
217
218 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "sctp_connectx() to re-establish a closed association - "
219 "SUCCESS");
220
221 closecxx . . $ close(7864480464b09eea).(sk);
222 closecxx . . $ close(7864480464b09eea).(sk1);
223 closecxx . . $ close(7864480464b09eea).(lstn_sk);
224
225 freecxx . . $ free(5d22bdacc48458e8).(tmp_addr);
226 return 0;
227 }