| 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 the graceful shutdown of an |
| 40 | * association. |
| 41 | */ |
| 42 | |
| 43 | #include <stdio.h> |
| 44 | #include <unistd.h> |
| 45 | #include <stdlib.h> |
| 46 | #include <string.h> |
| 47 | #include <sys/types.h> |
| 48 | #include <sys/socket.h> |
| 49 | #include <sys/uio.h> |
| 50 | #include <netinet/in.h> |
| 51 | #include <errno.h> |
| 52 | #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/ |
| 53 | #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/ |
| 54 | |
| 55 | char *TCIDcxx . . $ TCID. = __FILE__; |
| 56 | int TST_TOTALcxx . . $ TST_TOTAL. = 1; |
| 57 | int TST_CNTcxx . . $ TST_CNT. = 0; |
| 58 | |
| 59 | #define MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_shutdown.c:59:9`! 10 |
| 60 | |
| 61 | int |
| 62 | maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) |
| 63 | { |
| 64 | int svr_sk, clt_sk[MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_shutdown.c:59:9`!]; |
| 65 | sctp_assoc_tcxx . . $ sctp_assoc_t# svr_associd[MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_shutdown.c:59:9`!]; |
| 66 | sockaddr_storage_tcxx . . $ sockaddr_storage_t# svr_loop, clt_loop[MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_shutdown.c:59:9`!]; |
| 67 | struct ioveccxx . . $ iovec# iov; |
| 68 | struct msghdrcxx . . $ msghdr# inmessage; |
| 69 | struct msghdrcxx . . $ msghdr# outmessage; |
| 70 | char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(sctp_cmsg_data_t))]; |
| 71 | char outcmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(struct sctp_sndrcvinfo))]; |
| 72 | struct cmsghdrcxx . . $ cmsghdr# *cmsg; |
| 73 | struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *sinfo; |
| 74 | struct ioveccxx . . $ iovec# out_iov; |
| 75 | int error; |
| 76 | uint32_tcxx . . $ uint32_t# ppid; |
| 77 | uint32_tcxx . . $ uint32_t# stream; |
| 78 | struct sctp_assoc_changecxx . . $ sctp_assoc_change# *sac; |
| 79 | char *big_buffer; |
| 80 | int i; |
| 81 | char *message = "hello, world!\n"; |
| 82 | struct sctp_statuscxx . . $ sctp_status# status; |
| 83 | socklen_tcxx . . $ socklen_t# status_len; |
| 84 | |
| 85 | /* Rather than fflush() throughout the code, set stdout to |
| 86 | * be unbuffered. |
| 87 | */ |
| 88 | 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); |
| 89 | |
| 90 | /* Create and bind the server socket. */ |
| 91 | 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`!); |
| 92 | |
| 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_shutdown.c:59: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_shutdown.c:59: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_shutdown.c:59: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_shutdown.c:59: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 | /* Build up a msghdr structure we can use for all sending. */ |
| 181 | outmessage.msg_namecxx . . $ msghdr#msg_name. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 182 | outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = 0; |
| 183 | outmessage.msg_iovcxx . . $ msghdr#msg_iov. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!; |
| 184 | outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 0; |
| 185 | outmessage.msg_controlcxx . . $ msghdr#msg_control. = outcmsg; |
| 186 | outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(outcmsg); |
| 187 | outmessage.msg_flagscxx . . $ msghdr#msg_flags. = 0; |
| 188 | cmsg = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&outmessage); |
| 189 | cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!; |
| 190 | cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. = SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!; |
| 191 | cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(struct sctp_sndrcvinfo)); |
| 192 | outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len.; |
| 193 | sinfo = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg); |
| 194 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(sinfo, 0x00, sizeof(struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo#)); |
| 195 | sinfo->sinfo_flagscxx . . $ sctp_sndrcvinfo#sinfo_flags. |= SCTP_EOFcxx . . $ SCTP_EOF.; |
| 196 | |
| 197 | /* Shutdown all the associations of the server socket in a loop. */ |
| 198 | for (i = 0; i < MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_shutdown.c:59:9`!; i++) { |
| 199 | sinfo->sinfo_assoc_idcxx . . $ sctp_sndrcvinfo#sinfo_assoc_id. = svr_associd[i]; |
| 200 | |
| 201 | /* Verify that the association is present. */ |
| 202 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&status, 0, sizeof(struct sctp_statuscxx . . $ sctp_status#)); |
| 203 | status.sstat_assoc_idcxx . . $ sctp_status#sstat_assoc_id. = sinfo->sinfo_assoc_idcxx . . $ sctp_sndrcvinfo#sinfo_assoc_id.; |
| 204 | status_len = sizeof(struct sctp_statuscxx . . $ sctp_status#); |
| 205 | error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(svr_sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_STATUScxx . . $ `<external>/17169092326581286071/sctp.h:83:9`!, |
| 206 | &status, &status_len); |
| 207 | if (error) |
| 208 | tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, |
| 209 | "getsockopt(SCTP_STATUS): %s", |
| 210 | strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 211 | |
| 212 | /* Call sendmsg() to shutdown the association. */ |
| 213 | test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(svr_sk, &outmessage, 0, 0); |
| 214 | |
| 215 | /* Verify that the association is no longer present. */ |
| 216 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&status, 0, sizeof(struct sctp_statuscxx . . $ sctp_status#)); |
| 217 | status.sstat_assoc_idcxx . . $ sctp_status#sstat_assoc_id. = sinfo->sinfo_assoc_idcxx . . $ sctp_sndrcvinfo#sinfo_assoc_id.; |
| 218 | status_len = sizeof(struct sctp_statuscxx . . $ sctp_status#); |
| 219 | error = getsockoptcxx . . $ getsockopt(b79d9f11efef15f9).(svr_sk, SOL_SCTPcxx . . $ `src/include/netinet/sctp.h:48:9`!, SCTP_STATUScxx . . $ `<external>/17169092326581286071/sctp.h:83:9`!, |
| 220 | &status, &status_len); |
| 221 | if ((error != -1) && (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!)) |
| 222 | tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, |
| 223 | "getsockopt(SCTP_STATUS) " |
| 224 | "error:%d errno:%d", error, errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!); |
| 225 | } |
| 226 | |
| 227 | closecxx . . $ close(7864480464b09eea).(svr_sk); |
| 228 | |
| 229 | /* Get the shutdown complete notification. */ |
| 230 | for (i = 0; i < MAX_CLIENTScxx . . $ `src/func_tests/test_assoc_shutdown.c:59:9`!; i++) { |
| 231 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg); |
| 232 | error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(clt_sk[i], &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!); |
| 233 | test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error, |
| 234 | sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#), |
| 235 | SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, |
| 236 | SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.); |
| 237 | |
| 238 | closecxx . . $ close(7864480464b09eea).(clt_sk[i]); |
| 239 | } |
| 240 | |
| 241 | tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "Graceful shutdown of associations using SCTP_EOF"); |
| 242 | |
| 243 | freecxx . . $ free(5d22bdacc48458e8).(big_buffer); |
| 244 | /* Indicate successful completion. */ |
| 245 | return 0; |
| 246 | } |