Debian Codegraph @

src/func_tests/test_fragments.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 * La Monte H.P. Yarroll <[email protected]>
37 * Karl Knutson <[email protected]>
38 * Hui Huang <[email protected]>
39 * Jon Grimm <[email protected]>
40 * Sridhar Samudrala <[email protected]>
41 */
42
43 /* This is a functional test to verify the data fragmentation, reassembly
44 * support and SCTP_DISABLE_FRAGMENTS socket option.
45 * The following tests are done in sequence.
46 * - Verify SCTP_DISABLE_FRAGMENTS socket option by doing a setsockopt()
47 * followed by a getsockopt().
48 * - Verify that a message size exceeding the association fragmentation
49 * point cannot be sent when fragmentation is disabled.
50 * - Send and receive a set of messages that are bigger than the path mtu.
51 * The different message sizes to be tested are specified in the array
52 * msg_sizes[].
53 */
54
55 #include <stdio.h>
56 #include <unistd.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <sys/types.h>
60 #include <sys/socket.h>
61 #include <sys/uio.h>
62 #include <netinet/in.h>
63 #include <errno.h>
64 #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/
65 #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/
66
67 char *TCIDcxx . . $ TCID. = __FILE__;
68 int TST_TOTALcxx . . $ TST_TOTAL. = 4;
69 int TST_CNTcxx . . $ TST_CNT. = 0;
70
71 int msg_sizescxx . . $ msg_sizes.[] = {1353, 2000, 5000, 10000, 20000, 32768};
72
73 int
74 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
75 {
76 int sk1, sk2;
77 sockaddr_storage_tcxx . . $ sockaddr_storage_t# loop1;
78 sockaddr_storage_tcxx . . $ sockaddr_storage_t# loop2;
79 struct ioveccxx . . $ iovec# iov;
80 struct msghdrcxx . . $ msghdr# inmessage;
81 struct msghdrcxx . . $ msghdr# outmessage;
82 char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(sctp_cmsg_data_t))];
83 char outcmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(struct sctp_sndrcvinfo))];
84 struct cmsghdrcxx . . $ cmsghdr# *cmsg;
85 struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *sinfo;
86 struct ioveccxx . . $ iovec# out_iov;
87 int error, bytes_sent;
88 int pf_class;
89 uint32_tcxx . . $ uint32_t# ppid;
90 uint32_tcxx . . $ uint32_t# stream;
91 char *big_buffer;
92 int msg_len, msg_cnt, i;
93 void *msg_buf;
94 int disable_frag;
95 socklen_tcxx . . $ socklen_t# optlen;
96
97 /* Rather than fflush() throughout the code, set stdout to
98 * be unbuffered.
99 */
100 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);
101
102 /* Set some basic values which depend on the address family. */
103 #if TEST_V6
104 pf_class = PF_INET6;
105
106 loop1.v6.sin6_family = AF_INET6;
107 loop1.v6.sin6_addr = in6addr_loopbackcxx . . $ in6addr_loopback.;
108 loop1.v6.sin6_port = htons(SCTP_TESTPORT_1);
109
110 loop2.v6.sin6_family = AF_INET6;
111 loop2.v6.sin6_addr = in6addr_loopbackcxx . . $ in6addr_loopback.;
112 loop2.v6.sin6_port = htons(SCTP_TESTPORT_2);
113 #else
114 pf_class = PF_INETcxx . . $ `<external>/8962547315054503424/socket.h:45:9`!;
115
116 loop1.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
117 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`!;
118 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`!);
119
120 loop2.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
121 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`!;
122 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`!);
123 #endif /* TEST_V6 */
124
125 /* Create the two endpoints which will talk to each other. */
126 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`!);
127 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`!);
128
129 /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
130 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(sk1);
131 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(sk2);
132
133 /* Bind these sockets to the test ports. */
134 test_bindcxx . . $ test_bind(18e507052d945257).(sk1, &loop1.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(loop1));
135 test_bindcxx . . $ test_bind(18e507052d945257).(sk2, &loop2.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(loop2));
136
137 /* Mark sk2 as being able to accept new associations. */
138 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(sk2, 1);
139
140 /* Send the first message. This will create the association. */
141 outmessage.msg_namecxx . . $ msghdr#msg_name. = &loop2;
142 outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(loop2);
143 outmessage.msg_iovcxx . . $ msghdr#msg_iov. = &out_iov;
144 outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
145 outmessage.msg_controlcxx . . $ msghdr#msg_control. = outcmsg;
146 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(outcmsg);
147 outmessage.msg_flagscxx . . $ msghdr#msg_flags. = 0;
148 cmsg = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&outmessage);
149 cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!;
150 cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. = SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!;
151 cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(struct sctp_sndrcvinfo));
152 outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len.;
153 sinfo = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg);
154 memsetcxx . . $ memset(d1de1e4fb215f1c6).(sinfo, 0x00, sizeof(struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo#));
155 ppid = randcxx . . $ rand(b126dc7c1de90089).(); /* Choose an arbitrary value. */
156 stream = 1;
157 sinfo->sinfo_ppidcxx . . $ sctp_sndrcvinfo#sinfo_ppid. = ppid;
158 sinfo->sinfo_streamcxx . . $ sctp_sndrcvinfo#sinfo_stream. = stream;
159 msg_len = 10;
160 msg_buf = test_build_msgcxx . . $ test_build_msg(d1680a912d714170).(10);
161 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = msg_buf;
162 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = msg_len;
163 test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(sk1, &outmessage, 0, msg_len);
164
165
166 /* Initialize inmessage for all receives. */
167 big_buffer = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!);
168 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
169 iov.iov_basecxx . . $ iovec#iov_base. = big_buffer;
170 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!;
171 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
172 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
173 inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg;
174
175 /* Get the communication up message on sk2. */
176 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
177 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
178 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
179 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
180 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
181 #if 0
182 sac = (struct sctp_assoc_change *)iov.iov_base;
183 associd2 = sac->sac_assoc_id;
184 #endif
185 /* Get the communication up message on sk1. */
186 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
187 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk1, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
188 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
189 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
190 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
191 #if 0
192 sac = (struct sctp_assoc_change *)iov.iov_base;
193 associd1 = sac->sac_assoc_id;
194 #endif
195 /* Get the first message which was sent. */
196 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
197 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
198 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, msg_len, MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid);
199
200 freecxx . . $ free(5d22bdacc48458e8).(msg_buf);
201
202 /* Disable fragmentation. */
203 disable_frag = 1;
204 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(sk1, SCTP_DISABLE_FRAGMENTScxx . . $ `<external>/17169092326581286071/sctp.h:77:9`!, &disable_frag,
205 sizeof(disable_frag));
206
207 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "setsockopt(SCTP_DISABLE_FRAGMENTS)");
208
209 /* Do a getsockopt() and verify that fragmentation is disabled. */
210 disable_frag = 0;
211 optlen = sizeof(disable_frag);
212 error = test_getsockoptcxx . . $ test_getsockopt(55626bc83d624bdb).(sk1, SCTP_DISABLE_FRAGMENTScxx . . $ `<external>/17169092326581286071/sctp.h:77:9`!, &disable_frag,
213 &optlen);
214 if ((error != 0) && (disable_frag != 1))
215 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "getsockopt(SCTP_DISABLE_FRAGMENTS) "
216 "error:%d errno:%d disable_frag:%d",
217 error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!, disable_frag);
218
219 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "getsockopt(SCTP_DISABLE_FRAGMENTS)");
220
221 /* Try to send a messsage that exceeds association fragmentation point
222 * and verify that it fails.
223 */
224 msg_len = 100000;
225 msg_buf = test_build_msgcxx . . $ test_build_msg(d1680a912d714170).(msg_len);
226 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = msg_buf;
227 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = msg_len;
228 error = sendmsgcxx . . $ sendmsg(bc65c149164ceef5).(sk1, &outmessage, 0);
229 if ((error != -1) || (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EMSGSIZEcxx . . $ `<external>/17922322188510340118/errno.h:74:9`!))
230 tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "Send a message that exceeds "
231 "assoc frag point error:%d errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
232 freecxx . . $ free(5d22bdacc48458e8).(msg_buf);
233
234 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "Send a message that exceeds assoc frag point");
235
236 /* Enable Fragmentation. */
237 disable_frag = 0;
238 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(sk1, SCTP_DISABLE_FRAGMENTScxx . . $ `<external>/17169092326581286071/sctp.h:77:9`!, &disable_frag,
239 sizeof(disable_frag));
240
241 msg_cnt = sizeof(msg_sizescxx . . $ msg_sizes.) / sizeof(int);
242
243 /* Send and receive the messages of different sizes specified in the
244 * msg_sizes array in a loop.
245 */
246 for (i = 0; i < msg_cnt; i++) {
247
248 msg_len = msg_sizescxx . . $ msg_sizes.[i];
249 msg_buf = test_build_msgcxx . . $ test_build_msg(d1680a912d714170).(msg_len);
250 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = msg_buf;
251 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = msg_len;
252 bytes_sent = test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(sk1, &outmessage, 0, msg_len);
253
254 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TINFO, "Sent %d byte message", bytes_sent);
255
256 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
257 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
258 /* Handle Partial Reads. */
259 if (inmessage.msg_flagscxx . . $ msghdr#msg_flags. & MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!) {
260 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, bytes_sent,
261 MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid);
262 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TINFO, "Received %d byte message", error);
263 } else {
264 int remain;
265
266 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, error, 0,
267 stream, ppid);
268 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TINFO, "Received %d byte message", error);
269
270 /* Read the remaining message. */
271 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
272 remain = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
273 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, remain,
274 bytes_sent - error,
275 MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid);
276 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TINFO, "Received %d byte message", error);
277 }
278
279 freecxx . . $ free(5d22bdacc48458e8).(msg_buf);
280 }
281
282 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "Send/Receive fragmented messages");
283
284 /* Shut down the link. */
285 closecxx . . $ close(7864480464b09eea).(sk1);
286
287 /* Get the shutdown complete notification. */
288 inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg);
289 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
290 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
291 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
292 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.);
293
294 closecxx . . $ close(7864480464b09eea).(sk2);
295
296 freecxx . . $ free(5d22bdacc48458e8).(big_buffer);
297 /* Indicate successful completion. */
298 return 0;
299 }