| 1 | /* SCTP kernel Implementation |
| 2 | * (C) Copyright IBM Corp. 2002, 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 | * Copyright (c) 2001 La Monte H.P. Yarroll |
| 8 | * |
| 9 | * The SCTP implementation is free software; |
| 10 | * you can redistribute it and/or modify it under the terms of |
| 11 | * the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | * The SCTP implementation is distributed in the hope that it |
| 16 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 17 | * ************************ |
| 18 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 19 | * See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with GNU CC; see the file COPYING. If not, write to |
| 23 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
| 24 | * Boston, MA 02111-1307, USA. |
| 25 | * |
| 26 | * Please send any bug reports or fixes you make to the |
| 27 | * email address(es): |
| 28 | * lksctp developers <[email protected]> |
| 29 | * |
| 30 | * Or submit a bug report through the following website: |
| 31 | * https://github.com/sctp/lksctp-tools/ |
| 32 | * |
| 33 | * Any bugs reported to us we will try to fix... any fixes shared will |
| 34 | * be incorporated into the next SCTP release. |
| 35 | * |
| 36 | * Written or modified by: |
| 37 | * La Monte H.P. Yarroll <[email protected]> |
| 38 | * Karl Knutson <[email protected]> |
| 39 | * Jon Grimm <[email protected]> |
| 40 | * Sridhar Samudrala <[email protected]> |
| 41 | * Daisy Chang <[email protected]> |
| 42 | */ |
| 43 | |
| 44 | /* This is a functional test to verify binding a socket with INADDRY_ANY |
| 45 | * address and send messages. |
| 46 | */ |
| 47 | |
| 48 | #include <stdio.h> |
| 49 | #include <unistd.h> |
| 50 | #include <string.h> |
| 51 | #include <stdlib.h> |
| 52 | #include <sys/types.h> |
| 53 | #include <sys/socket.h> |
| 54 | #include <sys/uio.h> |
| 55 | #include <netinet/in.h> |
| 56 | #include <errno.h> |
| 57 | #include <netinet/sctp.h>cxx . . $ `<file>/src/include/netinet/sctp.h`/ |
| 58 | #include <sctputil.h>cxx . . $ `<file>/src/testlib/sctputil.h`/ |
| 59 | |
| 60 | char *TCIDcxx . . $ TCID. = __FILE__; |
| 61 | int TST_TOTALcxx . . $ TST_TOTAL. = 2; |
| 62 | int TST_CNTcxx . . $ TST_CNT. = 0; |
| 63 | |
| 64 | int |
| 65 | maincxx . . $ main(b126dc7c1de90089).(void) |
| 66 | { |
| 67 | int sk1, sk2; |
| 68 | sockaddr_storage_tcxx . . $ sockaddr_storage_t# loop; |
| 69 | sockaddr_storage_tcxx . . $ sockaddr_storage_t# anyaddr; |
| 70 | struct msghdrcxx . . $ msghdr# outmessage; |
| 71 | char incmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(sctp_cmsg_data_t))]; |
| 72 | char outcmsg[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(struct sctp_sndrcvinfo))]; |
| 73 | struct cmsghdrcxx . . $ cmsghdr# *cmsg; |
| 74 | struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *sinfo; |
| 75 | struct ioveccxx . . $ iovec# out_iov; |
| 76 | struct ioveccxx . . $ iovec# iov; |
| 77 | struct msghdrcxx . . $ msghdr# inmessage; |
| 78 | char *message = "hello, world!\n"; |
| 79 | char *telephone = "Watson, come here! I need you!\n"; |
| 80 | char *telephone_resp = "I already brought your coffee...\n"; |
| 81 | int error; |
| 82 | int pf_class; |
| 83 | uint32_tcxx . . $ uint32_t# ppid; |
| 84 | uint32_tcxx . . $ uint32_t# stream; |
| 85 | socklen_tcxx . . $ socklen_t# namelen; |
| 86 | |
| 87 | /* Rather than fflush() throughout the code, set stdout to |
| 88 | * be unbuffered. |
| 89 | */ |
| 90 | 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); |
| 91 | |
| 92 | /* Set some basic values which depend on the address family. */ |
| 93 | #if TEST_V6 |
| 94 | pf_class = PF_INET6; |
| 95 | |
| 96 | loop.v6.sin6_family = AF_INET6; |
| 97 | loop.v6.sin6_addr = (struct in6_addr)SCTP_IN6ADDR_LOOPBACK_INIT; |
| 98 | loop.v6.sin6_port = 0; |
| 99 | |
| 100 | anyaddr.v6.sin6_family = AF_INET6; |
| 101 | anyaddr.v6.sin6_addr = (struct in6_addr)SCTP_IN6ADDR_ANY_INIT; |
| 102 | anyaddr.v6.sin6_port = 0; |
| 103 | #else |
| 104 | pf_class = PF_INETcxx . . $ `<external>/8962547315054503424/socket.h:45:9`!; |
| 105 | |
| 106 | loop.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!; |
| 107 | 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`!; |
| 108 | loop.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_portcxx . . $ sockaddr_in#sin_port. = 0; |
| 109 | |
| 110 | anyaddr.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_familycxx . . $ sockaddr_in#sin_family. = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!; |
| 111 | anyaddr.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_addrcxx . . $ sockaddr_in#sin_addr..s_addrcxx . . $ in_addr#s_addr. = INADDR_ANYcxx . . $ `<external>/9581057695539925927/in.h:198:9`!; |
| 112 | anyaddr.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_portcxx . . $ sockaddr_in#sin_port. = 0; |
| 113 | #endif /* TEST_V6 */ |
| 114 | |
| 115 | /* Create the two endpoints which will talk to each other. */ |
| 116 | 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`!); |
| 117 | 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`!); |
| 118 | |
| 119 | /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */ |
| 120 | test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(sk1); |
| 121 | test_enable_assoc_changecxx . . $ test_enable_assoc_change(d4f767463ce0a6b3).(sk2); |
| 122 | |
| 123 | /* Bind these sockets to the test ports. */ |
| 124 | test_bindcxx . . $ test_bind(18e507052d945257).(sk1, &loop.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(loop)); |
| 125 | test_bindcxx . . $ test_bind(18e507052d945257).(sk2, &anyaddr.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., sizeof(anyaddr)); |
| 126 | |
| 127 | tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "bind INADDR_ANY address"); |
| 128 | |
| 129 | /* Mark sk2 as being able to accept new associations */ |
| 130 | test_listencxx . . $ test_listen(9b79fb6aee4c0440).(sk2, 1); |
| 131 | |
| 132 | /* Now use getsockaname() to retrieve the ephmeral ports. */ |
| 133 | namelen = sizeof(loop); |
| 134 | error = getsocknamecxx . . $ getsockname(46fcd054f4a4d98b).(sk1, &loop.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., &namelen); |
| 135 | if (error != 0) |
| 136 | tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "getsockname: %s", strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 137 | |
| 138 | namelen = sizeof(anyaddr); |
| 139 | error = getsocknamecxx . . $ getsockname(46fcd054f4a4d98b).(sk2, &anyaddr.sacxx . . $ $anonymous_type_f8e963888af85862_0#sa., &namelen); |
| 140 | if (error != 0) |
| 141 | tst_brkmcxx . . $ `src/testlib/sctputil.h:116:9`!(TBROK, tst_exit, "getsockname: %s", strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 142 | |
| 143 | #if TEST_V6 |
| 144 | loop.v6.sin6_port = anyaddr.v6.sin6_port; |
| 145 | #else |
| 146 | loop.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_portcxx . . $ sockaddr_in#sin_port. = anyaddr.v4cxx . . $ $anonymous_type_f8e963888af85862_0#v4..sin_portcxx . . $ sockaddr_in#sin_port.; |
| 147 | #endif |
| 148 | |
| 149 | /* Send the first message. This will create the association. */ |
| 150 | outmessage.msg_namecxx . . $ msghdr#msg_name. = &loop; |
| 151 | outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(loop); |
| 152 | outmessage.msg_iovcxx . . $ msghdr#msg_iov. = &out_iov; |
| 153 | outmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1; |
| 154 | outmessage.msg_controlcxx . . $ msghdr#msg_control. = outcmsg; |
| 155 | outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(outcmsg); |
| 156 | outmessage.msg_flagscxx . . $ msghdr#msg_flags. = 0; |
| 157 | cmsg = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&outmessage); |
| 158 | cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!; |
| 159 | cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. = SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!; |
| 160 | cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(struct sctp_sndrcvinfo)); |
| 161 | outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len.; |
| 162 | sinfo = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg); |
| 163 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(sinfo, 0x00, sizeof(struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo#)); |
| 164 | ppid = randcxx . . $ rand(b126dc7c1de90089).(); /* Choose an arbitrary value. */ |
| 165 | stream = 1; |
| 166 | sinfo->sinfo_ppidcxx . . $ sctp_sndrcvinfo#sinfo_ppid. = ppid; |
| 167 | sinfo->sinfo_streamcxx . . $ sctp_sndrcvinfo#sinfo_stream. = stream; |
| 168 | outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = message; |
| 169 | outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = strlencxx . . $ strlen(751346f8406fd082).(message) + 1; |
| 170 | test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(sk1, &outmessage, 0, strlencxx . . $ strlen(751346f8406fd082).(message)+1); |
| 171 | |
| 172 | /* Initialize inmessage for all receives. */ |
| 173 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&inmessage, 0, sizeof(inmessage)); |
| 174 | iov.iov_basecxx . . $ iovec#iov_base. = test_malloccxx . . $ test_malloc(bfcfa4d6b7f7ef64).(REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!); |
| 175 | iov.iov_lencxx . . $ iovec#iov_len. = REALLY_BIGcxx . . $ `src/testlib/sctputil.h:65:9`!; |
| 176 | inmessage.msg_iovcxx . . $ msghdr#msg_iov. = &iov; |
| 177 | inmessage.msg_iovlencxx . . $ msghdr#msg_iovlen. = 1; |
| 178 | inmessage.msg_controlcxx . . $ msghdr#msg_control. = incmsg; |
| 179 | |
| 180 | /* Get the communication up message on sk2. */ |
| 181 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg); |
| 182 | error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!); |
| 183 | test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error, |
| 184 | sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#), |
| 185 | SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.); |
| 186 | |
| 187 | /* Get the communication up message on sk1. */ |
| 188 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg); |
| 189 | error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk1, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!); |
| 190 | test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error, |
| 191 | sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#), |
| 192 | SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_COMM_UPcxx . . $ SCTP_COMM_UP.); |
| 193 | |
| 194 | /* Get the first message which was sent. */ |
| 195 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg); |
| 196 | error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!); |
| 197 | test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, strlencxx . . $ strlen(751346f8406fd082).(message) + 1, |
| 198 | MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid); |
| 199 | |
| 200 | /* Send 2 messages. */ |
| 201 | outmessage.msg_namecxx . . $ msghdr#msg_name. = &loop; |
| 202 | outmessage.msg_namelencxx . . $ msghdr#msg_namelen. = sizeof(loop); |
| 203 | outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(outcmsg); |
| 204 | outmessage.msg_flagscxx . . $ msghdr#msg_flags. = 0; |
| 205 | cmsg = CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&outmessage); |
| 206 | cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. = IPPROTO_SCTPcxx . . $ `<external>/9581057695539925927/in.h:87:9`!; |
| 207 | cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. = SCTP_SNDRCVcxx . . $ `<external>/17169092326581286071/sctp.h:333:9`!; |
| 208 | cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. = CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(struct sctp_sndrcvinfo)); |
| 209 | outmessage.msg_controllencxx . . $ msghdr#msg_controllen. = cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len.; |
| 210 | sinfo = (struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo# *)CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg); |
| 211 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(sinfo, 0x00, sizeof(struct sctp_sndrcvinfocxx . . $ sctp_sndrcvinfo#)); |
| 212 | ppid++; |
| 213 | stream++; |
| 214 | sinfo->sinfo_ppidcxx . . $ sctp_sndrcvinfo#sinfo_ppid. = ppid; |
| 215 | sinfo->sinfo_streamcxx . . $ sctp_sndrcvinfo#sinfo_stream. = stream; |
| 216 | outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = telephone; |
| 217 | outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = strlencxx . . $ strlen(751346f8406fd082).(telephone) + 1; |
| 218 | test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(sk1, &outmessage, 0, strlencxx . . $ strlen(751346f8406fd082).(telephone)+1); |
| 219 | |
| 220 | outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_basecxx . . $ iovec#iov_base. = telephone_resp; |
| 221 | outmessage.msg_iovcxx . . $ msghdr#msg_iov.->iov_lencxx . . $ iovec#iov_len. = strlencxx . . $ strlen(751346f8406fd082).(telephone_resp) + 1; |
| 222 | test_sendmsgcxx . . $ test_sendmsg(c45a39c477f473e).(sk1, &outmessage, 0, strlencxx . . $ strlen(751346f8406fd082).(telephone_resp)+1); |
| 223 | |
| 224 | /* Get those two messages. */ |
| 225 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg); |
| 226 | error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!); |
| 227 | test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, strlencxx . . $ strlen(751346f8406fd082).(telephone) + 1, |
| 228 | MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid); |
| 229 | |
| 230 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg); |
| 231 | error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!); |
| 232 | test_check_msg_datacxx . . $ test_check_msg_data(87a4c472fd2f0d28).(&inmessage, error, strlencxx . . $ strlen(751346f8406fd082).(telephone_resp) + 1, |
| 233 | MSG_EORcxx . . $ `<external>/8962547315054503424/socket.h:228:9`!, stream, ppid); |
| 234 | |
| 235 | /* Shut down the link. */ |
| 236 | closecxx . . $ close(7864480464b09eea).(sk1); |
| 237 | |
| 238 | /* Get the shutdown complete notification. */ |
| 239 | inmessage.msg_controllencxx . . $ msghdr#msg_controllen. = sizeof(incmsg); |
| 240 | error = test_recvmsgcxx . . $ test_recvmsg(2284ea468be03a33).(sk2, &inmessage, MSG_WAITALLcxx . . $ `<external>/8962547315054503424/socket.h:230:9`!); |
| 241 | test_check_msg_notificationcxx . . $ test_check_msg_notification(bda0d4705bf9b0d0).(&inmessage, error, |
| 242 | sizeof(struct sctp_assoc_changecxx . . $ sctp_assoc_change#), |
| 243 | SCTP_ASSOC_CHANGEcxx . . $ `<external>/17169092326581286071/sctp.h:666:9`!, SCTP_SHUTDOWN_COMPcxx . . $ SCTP_SHUTDOWN_COMP.); |
| 244 | |
| 245 | closecxx . . $ close(7864480464b09eea).(sk2); |
| 246 | |
| 247 | tst_resmcxx . . $ `src/testlib/sctputil.h:123:9`!(TPASS, "send msgs from a socket with INADDR_ANY bind address"); |
| 248 | |
| 249 | freecxx . . $ free(5d22bdacc48458e8).(iov.iov_basecxx . . $ iovec#iov_base.); |
| 250 | /* Indicate successful completion. */ |
| 251 | return 0; |
| 252 | } |