Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 1 | /* SCTP kernel Implementation |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 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 | * |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 8 | * The SCTP implementation is free software; |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 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 | * |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 14 | * The SCTP implementation is distributed in the hope that it |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 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 <lksctp-developers@lists.sourceforge.net> |
| 28 | * |
| 29 | * Or submit a bug report through the following website: |
| 30 | * http://www.sf.net/projects/lksctp |
| 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 <piggy@acm.org> |
| 37 | * Karl Knutson <karl@athena.chicago.il.us> |
| 38 | * Hui Huang <hui.huang@nokia.com> |
| 39 | * Jon Grimm <jgrimm@us.ibm.com> |
| 40 | * Sridhar Samudrala <samudrala@us.ibm.com> |
| 41 | */ |
| 42 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 43 | /* This is a basic functional test for the SCTP kernel |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 44 | * implementation state machine. |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 45 | */ |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 46 | |
| 47 | #include <stdio.h> |
| 48 | #include <unistd.h> |
| 49 | #include <stdlib.h> |
| 50 | #include <string.h> |
| 51 | #include <sys/types.h> |
| 52 | #include <sys/socket.h> |
| 53 | #include <sys/uio.h> |
| 54 | #include <netinet/in.h> |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 55 | #include <sys/errno.h> |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 56 | #include <errno.h> |
| 57 | #include <netinet/sctp.h> |
| 58 | #include <sctputil.h> |
| 59 | |
| 60 | char *TCID = __FILE__; |
| 61 | int TST_TOTAL = 15; |
| 62 | int TST_CNT = 0; |
| 63 | |
| 64 | int main(void) |
| 65 | { |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 66 | int sk1, sk2; |
| 67 | sockaddr_storage_t loop1; |
| 68 | sockaddr_storage_t loop2; |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 69 | sockaddr_storage_t msgname; |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 70 | struct iovec iov; |
| 71 | struct msghdr inmessage; |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 72 | struct msghdr outmessage; |
| 73 | char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))]; |
| 74 | char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; |
| 75 | struct cmsghdr *cmsg; |
| 76 | struct sctp_sndrcvinfo *sinfo; |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 77 | struct iovec out_iov; |
| 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, bytes_sent; |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 82 | int pf_class; |
| 83 | uint32_t ppid; |
| 84 | uint32_t stream; |
| 85 | sctp_assoc_t associd1, associd2; |
| 86 | struct sctp_assoc_change *sac; |
| 87 | char *big_buffer; |
| 88 | struct sockaddr *laddrs, *paddrs; |
| 89 | int n_laddrs, n_paddrs, i; |
| 90 | struct sockaddr *sa_addr; |
| 91 | struct sockaddr_in *in_addr; |
| 92 | struct sockaddr_in6 *in6_addr; |
| 93 | void *addr_buf; |
| 94 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 95 | /* Rather than fflush() throughout the code, set stdout to |
| 96 | * be unbuffered. |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 97 | */ |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 98 | setvbuf(stdout, NULL, _IONBF, 0); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 99 | |
| 100 | /* Set some basic values which depend on the address family. */ |
| 101 | #if TEST_V6 |
| 102 | pf_class = PF_INET6; |
| 103 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 104 | loop1.v6.sin6_family = AF_INET6; |
| 105 | loop1.v6.sin6_addr = (struct in6_addr)SCTP_IN6ADDR_ANY_INIT; |
| 106 | loop1.v6.sin6_port = htons(SCTP_TESTPORT_1); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 107 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 108 | loop2.v6.sin6_family = AF_INET6; |
| 109 | loop2.v6.sin6_addr = in6addr_loopback; |
| 110 | loop2.v6.sin6_port = htons(SCTP_TESTPORT_2); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 111 | #else |
| 112 | pf_class = PF_INET; |
| 113 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 114 | loop1.v4.sin_family = AF_INET; |
| 115 | loop1.v4.sin_addr.s_addr = INADDR_ANY; |
| 116 | loop1.v4.sin_port = htons(SCTP_TESTPORT_1); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 117 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 118 | loop2.v4.sin_family = AF_INET; |
| 119 | loop2.v4.sin_addr.s_addr = SCTP_IP_LOOPBACK; |
| 120 | loop2.v4.sin_port = htons(SCTP_TESTPORT_2); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 121 | #endif /* TEST_V6 */ |
| 122 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 123 | /* Create the two endpoints which will talk to each other. */ |
| 124 | sk1 = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP); |
| 125 | sk2 = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 126 | |
| 127 | tst_resm(TPASS, "socket"); |
| 128 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 129 | /* Bind these sockets to the test ports. */ |
| 130 | test_bind(sk1, &loop1.sa, sizeof(loop1)); |
| 131 | test_bind(sk2, &loop2.sa, sizeof(loop2)); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 132 | |
| 133 | tst_resm(TPASS, "bind"); |
| 134 | |
| 135 | /* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */ |
| 136 | test_enable_assoc_change(sk1); |
| 137 | test_enable_assoc_change(sk2); |
| 138 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 139 | /* Initialize inmessage for all receives. */ |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 140 | big_buffer = test_malloc(REALLY_BIG); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 141 | memset(&inmessage, 0, sizeof(inmessage)); |
| 142 | iov.iov_base = big_buffer; |
| 143 | iov.iov_len = REALLY_BIG; |
| 144 | inmessage.msg_iov = &iov; |
| 145 | inmessage.msg_iovlen = 1; |
| 146 | inmessage.msg_control = incmsg; |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 147 | inmessage.msg_name = &msgname; |
| 148 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 149 | /* Try to read on socket 2. This should fail since we are |
| 150 | * neither listening, nor established. |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 151 | */ |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 152 | inmessage.msg_controllen = sizeof(incmsg); |
| 153 | error = recvmsg(sk2, &inmessage, MSG_WAITALL); |
| 154 | if (error > 0) |
| 155 | tst_brkm(TBROK, tst_exit, "recvmsg on a socket neither" |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 156 | "listening nor established error: %d", error); |
| 157 | |
| 158 | tst_resm(TPASS, "recvmsg on a socket neither listening nor " |
| 159 | "established"); |
| 160 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 161 | /* Mark sk2 as being able to accept new associations. */ |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 162 | error = test_listen(sk2, 1); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 163 | |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 164 | tst_resm(TPASS, "listen"); |
| 165 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 166 | /* Send the first message. This will create the association. */ |
| 167 | outmessage.msg_name = &loop2; |
| 168 | outmessage.msg_namelen = sizeof(loop2); |
| 169 | outmessage.msg_iov = &out_iov; |
| 170 | outmessage.msg_iovlen = 1; |
| 171 | outmessage.msg_control = outcmsg; |
| 172 | outmessage.msg_controllen = sizeof(outcmsg); |
| 173 | outmessage.msg_flags = 0; |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 174 | cmsg = CMSG_FIRSTHDR(&outmessage); |
| 175 | cmsg->cmsg_level = IPPROTO_SCTP; |
| 176 | cmsg->cmsg_type = SCTP_SNDRCV; |
| 177 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); |
| 178 | outmessage.msg_controllen = cmsg->cmsg_len; |
| 179 | sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); |
| 180 | memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 181 | ppid = rand(); /* Choose an arbitrary value. */ |
| 182 | stream = 1; |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 183 | sinfo->sinfo_ppid = ppid; |
| 184 | sinfo->sinfo_stream = stream; |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 185 | outmessage.msg_iov->iov_base = message; |
| 186 | outmessage.msg_iov->iov_len = strlen(message) + 1; |
| 187 | test_sendmsg(sk1, &outmessage, 0, strlen(message)+1); |
| 188 | |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 189 | tst_resm(TPASS, "sendmsg with a valid msg_name"); |
| 190 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 191 | /* Get the communication up message on sk2. */ |
| 192 | inmessage.msg_controllen = sizeof(incmsg); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 193 | inmessage.msg_namelen = sizeof(msgname); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 194 | error = test_recvmsg(sk2, &inmessage, MSG_WAITALL); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 195 | test_check_msg_notification(&inmessage, error, |
| 196 | sizeof(struct sctp_assoc_change), |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 197 | SCTP_ASSOC_CHANGE, SCTP_COMM_UP); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 198 | #if TEST_V6 |
| 199 | |
| 200 | if (inmessage.msg_namelen != sizeof(struct sockaddr_in6)) { |
| 201 | DUMP_CORE; |
| 202 | } |
| 203 | if (msgname.v6.sin6_port != htons(SCTP_TESTPORT_1)) { |
| 204 | DUMP_CORE; |
| 205 | } |
| 206 | |
| 207 | if (msgname.v6.sin6_family != AF_INET6) { |
| 208 | DUMP_CORE; |
| 209 | } |
| 210 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 211 | if (memcmp(&msgname.v6.sin6_addr, &in6addr_loopback, |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 212 | sizeof(msgname.v6.sin6_addr))) { |
| 213 | DUMP_CORE; |
| 214 | } |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 215 | #else |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 216 | if (inmessage.msg_namelen != sizeof(struct sockaddr_in)) { |
| 217 | DUMP_CORE; |
| 218 | } |
| 219 | if (msgname.v4.sin_port != htons(SCTP_TESTPORT_1)) { |
| 220 | DUMP_CORE; |
| 221 | } |
| 222 | |
| 223 | if (msgname.v4.sin_family != AF_INET) { |
| 224 | DUMP_CORE; |
| 225 | } |
| 226 | if (msgname.v4.sin_addr.s_addr != SCTP_IP_LOOPBACK) { |
| 227 | DUMP_CORE; |
| 228 | } |
| 229 | #endif |
| 230 | sac = (struct sctp_assoc_change *)iov.iov_base; |
| 231 | associd2 = sac->sac_assoc_id; |
| 232 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 233 | /* Get the communication up message on sk1. */ |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 234 | iov.iov_base = big_buffer; |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 235 | iov.iov_len = REALLY_BIG; |
| 236 | inmessage.msg_control = incmsg; |
| 237 | inmessage.msg_controllen = sizeof(incmsg); |
| 238 | error = test_recvmsg(sk1, &inmessage, MSG_WAITALL); |
| 239 | test_check_msg_notification(&inmessage, error, |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 240 | sizeof(struct sctp_assoc_change), |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 241 | SCTP_ASSOC_CHANGE, SCTP_COMM_UP); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 242 | sac = (struct sctp_assoc_change *)iov.iov_base; |
| 243 | associd1 = sac->sac_assoc_id; |
| 244 | |
| 245 | tst_resm(TPASS, "recvmsg COMM_UP notifications"); |
| 246 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 247 | /* Get the first message which was sent. */ |
| 248 | inmessage.msg_controllen = sizeof(incmsg); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 249 | inmessage.msg_namelen = sizeof(msgname); |
| 250 | memset(&msgname, 0, sizeof(msgname)); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 251 | error = test_recvmsg(sk2, &inmessage, MSG_WAITALL); |
| 252 | test_check_msg_data(&inmessage, error, strlen(message) + 1, |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 253 | MSG_EOR, stream, ppid); |
| 254 | #if TEST_V6 |
| 255 | |
| 256 | if (inmessage.msg_namelen != sizeof(struct sockaddr_in6)) { |
| 257 | DUMP_CORE; |
| 258 | } |
| 259 | if (msgname.v6.sin6_port != htons(SCTP_TESTPORT_1)) { |
| 260 | DUMP_CORE; |
| 261 | } |
| 262 | |
| 263 | if (msgname.v6.sin6_family != AF_INET6) { |
| 264 | DUMP_CORE; |
| 265 | } |
| 266 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 267 | if (memcmp(&msgname.v6.sin6_addr, &in6addr_loopback, |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 268 | sizeof(msgname.v6.sin6_addr))) { |
| 269 | DUMP_CORE; |
| 270 | } |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 271 | #else |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 272 | if (inmessage.msg_namelen != sizeof(struct sockaddr_in)) { |
| 273 | DUMP_CORE; |
| 274 | } |
| 275 | if (msgname.v4.sin_port != htons(SCTP_TESTPORT_1)) { |
| 276 | DUMP_CORE; |
| 277 | } |
| 278 | if (msgname.v4.sin_family != AF_INET) { |
| 279 | DUMP_CORE; |
| 280 | } |
| 281 | if (msgname.v4.sin_addr.s_addr != SCTP_IP_LOOPBACK) { |
| 282 | DUMP_CORE; |
| 283 | } |
| 284 | #endif |
| 285 | |
| 286 | /* Try to send a message with NULL msg_name and associd, should fail */ |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 287 | outmessage.msg_controllen = sizeof(outcmsg); |
| 288 | outmessage.msg_flags = 0; |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 289 | cmsg = CMSG_FIRSTHDR(&outmessage); |
| 290 | cmsg->cmsg_level = IPPROTO_SCTP; |
| 291 | cmsg->cmsg_type = SCTP_SNDRCV; |
| 292 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); |
| 293 | outmessage.msg_controllen = cmsg->cmsg_len; |
| 294 | sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); |
| 295 | memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo)); |
| 296 | ppid++; |
| 297 | stream++; |
| 298 | sinfo->sinfo_ppid = ppid; |
| 299 | sinfo->sinfo_stream = stream; |
| 300 | outmessage.msg_iov->iov_base = telephone; |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 301 | outmessage.msg_iov->iov_len = strlen(telephone) + 1; |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 302 | outmessage.msg_name = NULL; |
| 303 | outmessage.msg_namelen = 0; |
| 304 | bytes_sent = sendmsg(sk1, &outmessage, MSG_NOSIGNAL); |
| 305 | if ((bytes_sent > 0) || (EPIPE != errno)) |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 306 | tst_brkm(TBROK, tst_exit, "sendmsg with NULL associd and " |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 307 | "NULL msg_name error:%d errno:%d", error, errno); |
| 308 | |
| 309 | tst_resm(TPASS, "sendmsg with NULL associd and NULL msg_name"); |
| 310 | |
| 311 | /* Fill in a incorrect assoc_id, which should cause an error. */ |
| 312 | sinfo->sinfo_assoc_id = associd2; |
| 313 | bytes_sent = sendmsg(sk1, &outmessage, MSG_NOSIGNAL); |
| 314 | if ((bytes_sent > 0) || (EPIPE != errno)) |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 315 | tst_brkm(TBROK, tst_exit, "sendmsg with incorrect associd " |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 316 | "error:%d errno:%d", error, errno); |
| 317 | |
| 318 | tst_resm(TPASS, "sendmsg with incorrect associd"); |
| 319 | |
| 320 | /* Fill in a correct assoc_id and get back to the normal testing. */ |
| 321 | sinfo->sinfo_assoc_id = associd1; |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 322 | /* Send two more messages, to cause a second SACK. */ |
| 323 | test_sendmsg(sk1, &outmessage, 0, strlen(telephone)+1); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 324 | |
| 325 | outmessage.msg_name = &loop2; |
| 326 | outmessage.msg_namelen = sizeof(loop2); |
| 327 | outmessage.msg_iov->iov_base = telephone_resp; |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 328 | outmessage.msg_iov->iov_len = strlen(telephone_resp) + 1; |
| 329 | test_sendmsg(sk1, &outmessage, 0, strlen(telephone_resp)+1); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 330 | |
| 331 | tst_resm(TPASS, "sendmsg with valid associd"); |
| 332 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 333 | /* Get those two messages. */ |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 334 | inmessage.msg_controllen = sizeof(incmsg); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 335 | error = test_recvmsg(sk2, &inmessage, MSG_WAITALL); |
| 336 | test_check_msg_data(&inmessage, error, strlen(telephone) + 1, |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 337 | MSG_EOR, stream, ppid); |
| 338 | |
| 339 | inmessage.msg_controllen = sizeof(incmsg); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 340 | error = test_recvmsg(sk2, &inmessage, MSG_WAITALL); |
| 341 | test_check_msg_data(&inmessage, error, strlen(telephone_resp) + 1, |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 342 | MSG_EOR, stream, ppid); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 343 | |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 344 | tst_resm(TPASS, "recvmsg"); |
| 345 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 346 | n_laddrs = sctp_getladdrs(sk1, associd1, &laddrs); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 347 | if (n_laddrs <= 0) |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 348 | tst_brkm(TBROK, tst_exit, "sctp_getladdrs: %s", |
| 349 | strerror(errno)); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 350 | |
| 351 | tst_resm(TPASS, "sctp_getladdrs"); |
| 352 | |
| 353 | addr_buf = (void *)laddrs; |
| 354 | for (i = 0; i < n_laddrs; i++) { |
| 355 | sa_addr = (struct sockaddr *)addr_buf; |
| 356 | if (AF_INET == sa_addr->sa_family) { |
| 357 | in_addr = (struct sockaddr_in *)sa_addr; |
mridge | 64a341f | 2006-01-03 19:16:46 +0000 | [diff] [blame] | 358 | tst_resm(TINFO, "LOCAL ADDR %d.%d.%d.%d PORT %d", |
| 359 | NIPQUAD(in_addr->sin_addr), |
| 360 | ntohs(in_addr->sin_port)); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 361 | addr_buf += sizeof(struct sockaddr_in); |
| 362 | } else { |
| 363 | in6_addr = (struct sockaddr_in6 *)sa_addr; |
| 364 | tst_resm(TINFO, |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 365 | "LOCAL ADDR %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x PORT %d", |
| 366 | NIP6(in6_addr->sin6_addr), |
| 367 | ntohs(in6_addr->sin6_port)); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 368 | addr_buf += sizeof(struct sockaddr_in6); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | sctp_freeladdrs(laddrs); |
| 373 | |
| 374 | tst_resm(TPASS, "sctp_freeladdrs"); |
| 375 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 376 | n_paddrs = sctp_getpaddrs(sk1, associd1, &paddrs); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 377 | if (n_paddrs <= 0) |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 378 | tst_brkm(TBROK, tst_exit, "sctp_getpaddrs: %s", |
| 379 | strerror(errno)); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 380 | |
| 381 | tst_resm(TPASS, "sctp_getpaddrs"); |
| 382 | |
| 383 | addr_buf = (void *)paddrs; |
| 384 | for (i = 0; i < n_paddrs; i++) { |
| 385 | sa_addr = (struct sockaddr *)addr_buf; |
| 386 | if (AF_INET == sa_addr->sa_family) { |
| 387 | in_addr = (struct sockaddr_in *)sa_addr; |
mridge | 64a341f | 2006-01-03 19:16:46 +0000 | [diff] [blame] | 388 | tst_resm(TINFO, "PEER ADDR %d.%d.%d.%d PORT %d", |
| 389 | NIPQUAD(in_addr->sin_addr), |
| 390 | ntohs(in_addr->sin_port)); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 391 | addr_buf += sizeof(struct sockaddr_in); |
| 392 | } else { |
| 393 | in6_addr = (struct sockaddr_in6 *)sa_addr; |
| 394 | tst_resm(TINFO, |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 395 | "PEER ADDR %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x PORT %d", |
| 396 | NIP6(in6_addr->sin6_addr), |
| 397 | ntohs(in6_addr->sin6_port)); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 398 | addr_buf += sizeof(struct sockaddr_in6); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | sctp_freepaddrs(paddrs); |
| 403 | |
| 404 | tst_resm(TPASS, "sctp_freepaddrs"); |
| 405 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 406 | /* Shut down the link. */ |
| 407 | close(sk1); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 408 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 409 | /* Get the shutdown complete notification. */ |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 410 | inmessage.msg_controllen = sizeof(incmsg); |
| 411 | inmessage.msg_namelen = sizeof(msgname); |
| 412 | memset(&msgname, 0, sizeof(msgname)); |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 413 | error = test_recvmsg(sk2, &inmessage, MSG_WAITALL); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 414 | test_check_msg_notification(&inmessage, error, |
| 415 | sizeof(struct sctp_assoc_change), |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 416 | SCTP_ASSOC_CHANGE, SCTP_SHUTDOWN_COMP); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 417 | #if TEST_V6 |
| 418 | |
| 419 | if (inmessage.msg_namelen != sizeof(struct sockaddr_in6)) { |
| 420 | DUMP_CORE; |
| 421 | } |
| 422 | if (msgname.v6.sin6_port != htons(SCTP_TESTPORT_1)) { |
| 423 | DUMP_CORE; |
| 424 | } |
| 425 | |
| 426 | if (msgname.v6.sin6_family != AF_INET6) { |
| 427 | DUMP_CORE; |
| 428 | } |
| 429 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 430 | if (memcmp(&msgname.v6.sin6_addr, &in6addr_loopback, |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 431 | sizeof(msgname.v6.sin6_addr))) { |
| 432 | DUMP_CORE; |
| 433 | } |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 434 | #else |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 435 | if (inmessage.msg_namelen != sizeof(struct sockaddr_in)) { |
| 436 | DUMP_CORE; |
| 437 | } |
| 438 | if (msgname.v4.sin_port != htons(SCTP_TESTPORT_1)) { |
| 439 | DUMP_CORE; |
| 440 | } |
| 441 | |
| 442 | if (msgname.v4.sin_family != AF_INET) { |
| 443 | DUMP_CORE; |
| 444 | } |
| 445 | if (msgname.v4.sin_addr.s_addr != SCTP_IP_LOOPBACK) { |
| 446 | DUMP_CORE; |
| 447 | } |
| 448 | #endif |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 449 | |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 450 | tst_resm(TPASS, "recvmsg SHUTDOWN_COMP notification"); |
| 451 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 452 | close(sk2); |
uid52817 | 89de9aa | 2003-10-23 18:42:24 +0000 | [diff] [blame] | 453 | |
Simon Xu | 6f22494 | 2013-12-06 11:51:16 +0800 | [diff] [blame] | 454 | /* Indicate successful completion. */ |
| 455 | return 0; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 456 | } |