Debian Codegraph @

src/func_tests/test_autoclose.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 * Sridhar Samudrala <[email protected]>
37 */
38
39 /* This is a Functional Test to verify autoclose functionality and the
40 * socket option SCTP_AUTOCLOSE that can be used to specify the duration in
41 * which an idle association is automatically closed.
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 int
61 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
62 {
63 int sk1, sk2;
64 sockaddr_storage_tcxx . . $ sockaddr_storage_t# loop1, loop2;
65 struct msghdrcxx . . $ msghdr# inmessage, outmessage;
66 struct ioveccxx . . $ iovec# iov, out_iov;
67 int error;
68 char *big_buffer;
69 char *message = "hello, world!\n";
70 uint32_tcxx . . $ uint32_t# autoclose;
71
72 /* Rather than fflush() throughout the code, set stdout to
73 * be unbuffered.
74 */
75 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);
76
77 loop1.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
78 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`!;
79 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`!);
80
81 loop2.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!;
82 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`!;
83 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`!);
84
85 /* Create the two endpoints which will talk to each other. */
86 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`!);
87 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`!);
88
89 /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
90 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(sk1);
91 test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(sk2);
92
93 /* Bind these sockets to the test ports. */
94 test_bindcxx . . $ test_bind(18e507052d945257).(sk1, &loop1.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(loop1));
95 test_bindcxx . . $ test_bind(18e507052d945257).(sk2, &loop2.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(loop2));
96
97 /* Mark sk2 as being able to accept new associations. */
98 test_listencxx . . $ test_listen(9b79fb6aee4c0440).(sk2, 1);
99
100 /* Set the autoclose duration for the associations created on sk1
101 * and sk2 to be 5 seconds.
102 */
103 autoclose = 5;
104 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(sk1, SCTP_AUTOCLOSEcxx . . $ `<external>/17169092326581286071/sctp.h:73:9`!, &autoclose, sizeof(autoclose));
105 test_setsockoptcxx . . $ test_setsockopt(57908ac6eaa2fecc).(sk2, SCTP_AUTOCLOSEcxx . . $ `<external>/17169092326581286071/sctp.h:73:9`!, &autoclose, sizeof(autoclose));
106
107 /* Send the first message. This will create the association. */
108 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&outmessage, 0, sizeof(outmessage));
109 outmessage.msg_namecxx . . $ msghdr#msg_name. = &loop2;
110 outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(loop2);
111 outmessage.msg_iovcxx . . $ msghdr#msg_iov. = &out_iov;
112 outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
113 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = message;
114 outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = strlencxx . . $ strlen(751346f8406fd082).(message) + 1;
115
116 test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(sk1, &outmessage, 0, strlencxx . . $ strlen(751346f8406fd082).(message)+1);
117
118 /* Initialize inmessage for all receives. */
119 big_buffer = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!);
120 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage));
121 iov.iov_basecxx . . $ iovec#iov_base. = big_buffer;
122 iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!;
123 inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov;
124 inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1;
125 inmessage.msg_controlcxx . . $ msghdr#msg_control. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
126
127 /* Get the communication up message on sk2. */
128 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
129 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
130 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
131 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
132
133 /* Get the communication up message on sk1. */
134 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk1, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
135 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
136 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
137 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.);
138
139 /* Get the first message which was sent. */
140 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
141 test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, strlencxx . . $ strlen(751346f8406fd082).(message) + 1,
142 MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!|MSG_CTRUNCcxx . . $ `<external>/8962547315054503424/socket.h:220:9`!, 0, 0);
143
144 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TINFO, "Waiting for the associations to close automatically "
145 "in 5 secs");
146
147 /* Get the shutdown complete notification from sk1. */
148 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk1, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
149 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
150 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
151 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.);
152
153 /* Get the shutdown complete notification from sk2. */
154 error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!);
155 test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error,
156 sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#),
157 SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.);
158
159 tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "Autoclose of associations");
160
161 /* Shut down the link. */
162 closecxx . . $ close(7864480464b09eea).(sk1);
163 closecxx . . $ close(7864480464b09eea).(sk2);
164
165 freecxx . . $ free(5d22bdacc48458e8).(big_buffer);
166 /* Indicate successful completion. */
167 return 0;
168 }