blob: b8d4eaea1aca457d2018d1105510da4ee5b1a41f [file] [log] [blame]
Simon Xu6f224942013-12-06 11:51:16 +08001/* SCTP kernel Implementation
uid5281789de9aa2003-10-23 18:42:24 +00002 * (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 Xu6f224942013-12-06 11:51:16 +08008 * The SCTP implementation is free software;
uid5281789de9aa2003-10-23 18:42:24 +00009 * 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 Xu6f224942013-12-06 11:51:16 +080014 * The SCTP implementation is distributed in the hope that it
uid5281789de9aa2003-10-23 18:42:24 +000015 * 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 Xu6f224942013-12-06 11:51:16 +080043/* This is a basic functional test for the SCTP kernel
uid5281789de9aa2003-10-23 18:42:24 +000044 * implementation state machine.
Simon Xu6f224942013-12-06 11:51:16 +080045 */
uid5281789de9aa2003-10-23 18:42:24 +000046
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 Xu6f224942013-12-06 11:51:16 +080055#include <sys/errno.h>
uid5281789de9aa2003-10-23 18:42:24 +000056#include <errno.h>
57#include <netinet/sctp.h>
58#include <sctputil.h>
59
60char *TCID = __FILE__;
61int TST_TOTAL = 15;
62int TST_CNT = 0;
63
64int main(void)
65{
Simon Xu6f224942013-12-06 11:51:16 +080066 int sk1, sk2;
67 sockaddr_storage_t loop1;
68 sockaddr_storage_t loop2;
uid5281789de9aa2003-10-23 18:42:24 +000069 sockaddr_storage_t msgname;
Simon Xu6f224942013-12-06 11:51:16 +080070 struct iovec iov;
71 struct msghdr inmessage;
uid5281789de9aa2003-10-23 18:42:24 +000072 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 Xu6f224942013-12-06 11:51:16 +080077 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;
uid5281789de9aa2003-10-23 18:42:24 +000082 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 Xu6f224942013-12-06 11:51:16 +080095 /* Rather than fflush() throughout the code, set stdout to
96 * be unbuffered.
uid5281789de9aa2003-10-23 18:42:24 +000097 */
Simon Xu6f224942013-12-06 11:51:16 +080098 setvbuf(stdout, NULL, _IONBF, 0);
uid5281789de9aa2003-10-23 18:42:24 +000099
100 /* Set some basic values which depend on the address family. */
101#if TEST_V6
102 pf_class = PF_INET6;
103
Simon Xu6f224942013-12-06 11:51:16 +0800104 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);
uid5281789de9aa2003-10-23 18:42:24 +0000107
Simon Xu6f224942013-12-06 11:51:16 +0800108 loop2.v6.sin6_family = AF_INET6;
109 loop2.v6.sin6_addr = in6addr_loopback;
110 loop2.v6.sin6_port = htons(SCTP_TESTPORT_2);
uid5281789de9aa2003-10-23 18:42:24 +0000111#else
112 pf_class = PF_INET;
113
Simon Xu6f224942013-12-06 11:51:16 +0800114 loop1.v4.sin_family = AF_INET;
115 loop1.v4.sin_addr.s_addr = INADDR_ANY;
116 loop1.v4.sin_port = htons(SCTP_TESTPORT_1);
uid5281789de9aa2003-10-23 18:42:24 +0000117
Simon Xu6f224942013-12-06 11:51:16 +0800118 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);
uid5281789de9aa2003-10-23 18:42:24 +0000121#endif /* TEST_V6 */
122
Simon Xu6f224942013-12-06 11:51:16 +0800123 /* 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);
uid5281789de9aa2003-10-23 18:42:24 +0000126
127 tst_resm(TPASS, "socket");
128
Simon Xu6f224942013-12-06 11:51:16 +0800129 /* Bind these sockets to the test ports. */
130 test_bind(sk1, &loop1.sa, sizeof(loop1));
131 test_bind(sk2, &loop2.sa, sizeof(loop2));
uid5281789de9aa2003-10-23 18:42:24 +0000132
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 Xu6f224942013-12-06 11:51:16 +0800139 /* Initialize inmessage for all receives. */
uid5281789de9aa2003-10-23 18:42:24 +0000140 big_buffer = test_malloc(REALLY_BIG);
Simon Xu6f224942013-12-06 11:51:16 +0800141 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;
uid5281789de9aa2003-10-23 18:42:24 +0000147 inmessage.msg_name = &msgname;
148
Simon Xu6f224942013-12-06 11:51:16 +0800149 /* Try to read on socket 2. This should fail since we are
150 * neither listening, nor established.
uid5281789de9aa2003-10-23 18:42:24 +0000151 */
Simon Xu6f224942013-12-06 11:51:16 +0800152 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"
uid5281789de9aa2003-10-23 18:42:24 +0000156 "listening nor established error: %d", error);
157
158 tst_resm(TPASS, "recvmsg on a socket neither listening nor "
159 "established");
160
Simon Xu6f224942013-12-06 11:51:16 +0800161 /* Mark sk2 as being able to accept new associations. */
uid5281789de9aa2003-10-23 18:42:24 +0000162 error = test_listen(sk2, 1);
Simon Xu6f224942013-12-06 11:51:16 +0800163
uid5281789de9aa2003-10-23 18:42:24 +0000164 tst_resm(TPASS, "listen");
165
Simon Xu6f224942013-12-06 11:51:16 +0800166 /* 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;
uid5281789de9aa2003-10-23 18:42:24 +0000174 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 Xu6f224942013-12-06 11:51:16 +0800181 ppid = rand(); /* Choose an arbitrary value. */
182 stream = 1;
uid5281789de9aa2003-10-23 18:42:24 +0000183 sinfo->sinfo_ppid = ppid;
184 sinfo->sinfo_stream = stream;
Simon Xu6f224942013-12-06 11:51:16 +0800185 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
uid5281789de9aa2003-10-23 18:42:24 +0000189 tst_resm(TPASS, "sendmsg with a valid msg_name");
190
Simon Xu6f224942013-12-06 11:51:16 +0800191 /* Get the communication up message on sk2. */
192 inmessage.msg_controllen = sizeof(incmsg);
uid5281789de9aa2003-10-23 18:42:24 +0000193 inmessage.msg_namelen = sizeof(msgname);
Simon Xu6f224942013-12-06 11:51:16 +0800194 error = test_recvmsg(sk2, &inmessage, MSG_WAITALL);
uid5281789de9aa2003-10-23 18:42:24 +0000195 test_check_msg_notification(&inmessage, error,
196 sizeof(struct sctp_assoc_change),
Simon Xu6f224942013-12-06 11:51:16 +0800197 SCTP_ASSOC_CHANGE, SCTP_COMM_UP);
uid5281789de9aa2003-10-23 18:42:24 +0000198#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 Xu6f224942013-12-06 11:51:16 +0800211 if (memcmp(&msgname.v6.sin6_addr, &in6addr_loopback,
uid5281789de9aa2003-10-23 18:42:24 +0000212 sizeof(msgname.v6.sin6_addr))) {
213 DUMP_CORE;
214 }
Simon Xu6f224942013-12-06 11:51:16 +0800215#else
uid5281789de9aa2003-10-23 18:42:24 +0000216 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 Xu6f224942013-12-06 11:51:16 +0800233 /* Get the communication up message on sk1. */
uid5281789de9aa2003-10-23 18:42:24 +0000234 iov.iov_base = big_buffer;
Simon Xu6f224942013-12-06 11:51:16 +0800235 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,
uid5281789de9aa2003-10-23 18:42:24 +0000240 sizeof(struct sctp_assoc_change),
Simon Xu6f224942013-12-06 11:51:16 +0800241 SCTP_ASSOC_CHANGE, SCTP_COMM_UP);
uid5281789de9aa2003-10-23 18:42:24 +0000242 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 Xu6f224942013-12-06 11:51:16 +0800247 /* Get the first message which was sent. */
248 inmessage.msg_controllen = sizeof(incmsg);
uid5281789de9aa2003-10-23 18:42:24 +0000249 inmessage.msg_namelen = sizeof(msgname);
250 memset(&msgname, 0, sizeof(msgname));
Simon Xu6f224942013-12-06 11:51:16 +0800251 error = test_recvmsg(sk2, &inmessage, MSG_WAITALL);
252 test_check_msg_data(&inmessage, error, strlen(message) + 1,
uid5281789de9aa2003-10-23 18:42:24 +0000253 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 Xu6f224942013-12-06 11:51:16 +0800267 if (memcmp(&msgname.v6.sin6_addr, &in6addr_loopback,
uid5281789de9aa2003-10-23 18:42:24 +0000268 sizeof(msgname.v6.sin6_addr))) {
269 DUMP_CORE;
270 }
Simon Xu6f224942013-12-06 11:51:16 +0800271#else
uid5281789de9aa2003-10-23 18:42:24 +0000272 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 Xu6f224942013-12-06 11:51:16 +0800287 outmessage.msg_controllen = sizeof(outcmsg);
288 outmessage.msg_flags = 0;
uid5281789de9aa2003-10-23 18:42:24 +0000289 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 Xu6f224942013-12-06 11:51:16 +0800301 outmessage.msg_iov->iov_len = strlen(telephone) + 1;
uid5281789de9aa2003-10-23 18:42:24 +0000302 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 Xu6f224942013-12-06 11:51:16 +0800306 tst_brkm(TBROK, tst_exit, "sendmsg with NULL associd and "
uid5281789de9aa2003-10-23 18:42:24 +0000307 "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 Xu6f224942013-12-06 11:51:16 +0800315 tst_brkm(TBROK, tst_exit, "sendmsg with incorrect associd "
uid5281789de9aa2003-10-23 18:42:24 +0000316 "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 Xu6f224942013-12-06 11:51:16 +0800322 /* Send two more messages, to cause a second SACK. */
323 test_sendmsg(sk1, &outmessage, 0, strlen(telephone)+1);
uid5281789de9aa2003-10-23 18:42:24 +0000324
325 outmessage.msg_name = &loop2;
326 outmessage.msg_namelen = sizeof(loop2);
327 outmessage.msg_iov->iov_base = telephone_resp;
Simon Xu6f224942013-12-06 11:51:16 +0800328 outmessage.msg_iov->iov_len = strlen(telephone_resp) + 1;
329 test_sendmsg(sk1, &outmessage, 0, strlen(telephone_resp)+1);
uid5281789de9aa2003-10-23 18:42:24 +0000330
331 tst_resm(TPASS, "sendmsg with valid associd");
332
Simon Xu6f224942013-12-06 11:51:16 +0800333 /* Get those two messages. */
uid5281789de9aa2003-10-23 18:42:24 +0000334 inmessage.msg_controllen = sizeof(incmsg);
Simon Xu6f224942013-12-06 11:51:16 +0800335 error = test_recvmsg(sk2, &inmessage, MSG_WAITALL);
336 test_check_msg_data(&inmessage, error, strlen(telephone) + 1,
uid5281789de9aa2003-10-23 18:42:24 +0000337 MSG_EOR, stream, ppid);
338
339 inmessage.msg_controllen = sizeof(incmsg);
Simon Xu6f224942013-12-06 11:51:16 +0800340 error = test_recvmsg(sk2, &inmessage, MSG_WAITALL);
341 test_check_msg_data(&inmessage, error, strlen(telephone_resp) + 1,
uid5281789de9aa2003-10-23 18:42:24 +0000342 MSG_EOR, stream, ppid);
Simon Xu6f224942013-12-06 11:51:16 +0800343
uid5281789de9aa2003-10-23 18:42:24 +0000344 tst_resm(TPASS, "recvmsg");
345
Simon Xu6f224942013-12-06 11:51:16 +0800346 n_laddrs = sctp_getladdrs(sk1, associd1, &laddrs);
uid5281789de9aa2003-10-23 18:42:24 +0000347 if (n_laddrs <= 0)
Simon Xu6f224942013-12-06 11:51:16 +0800348 tst_brkm(TBROK, tst_exit, "sctp_getladdrs: %s",
349 strerror(errno));
uid5281789de9aa2003-10-23 18:42:24 +0000350
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;
mridge64a341f2006-01-03 19:16:46 +0000358 tst_resm(TINFO, "LOCAL ADDR %d.%d.%d.%d PORT %d",
359 NIPQUAD(in_addr->sin_addr),
360 ntohs(in_addr->sin_port));
uid5281789de9aa2003-10-23 18:42:24 +0000361 addr_buf += sizeof(struct sockaddr_in);
362 } else {
363 in6_addr = (struct sockaddr_in6 *)sa_addr;
364 tst_resm(TINFO,
Simon Xu6f224942013-12-06 11:51:16 +0800365 "LOCAL ADDR %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x PORT %d",
366 NIP6(in6_addr->sin6_addr),
367 ntohs(in6_addr->sin6_port));
uid5281789de9aa2003-10-23 18:42:24 +0000368 addr_buf += sizeof(struct sockaddr_in6);
369 }
370 }
371
372 sctp_freeladdrs(laddrs);
373
374 tst_resm(TPASS, "sctp_freeladdrs");
375
Simon Xu6f224942013-12-06 11:51:16 +0800376 n_paddrs = sctp_getpaddrs(sk1, associd1, &paddrs);
uid5281789de9aa2003-10-23 18:42:24 +0000377 if (n_paddrs <= 0)
Simon Xu6f224942013-12-06 11:51:16 +0800378 tst_brkm(TBROK, tst_exit, "sctp_getpaddrs: %s",
379 strerror(errno));
uid5281789de9aa2003-10-23 18:42:24 +0000380
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;
mridge64a341f2006-01-03 19:16:46 +0000388 tst_resm(TINFO, "PEER ADDR %d.%d.%d.%d PORT %d",
389 NIPQUAD(in_addr->sin_addr),
390 ntohs(in_addr->sin_port));
uid5281789de9aa2003-10-23 18:42:24 +0000391 addr_buf += sizeof(struct sockaddr_in);
392 } else {
393 in6_addr = (struct sockaddr_in6 *)sa_addr;
394 tst_resm(TINFO,
Simon Xu6f224942013-12-06 11:51:16 +0800395 "PEER ADDR %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x PORT %d",
396 NIP6(in6_addr->sin6_addr),
397 ntohs(in6_addr->sin6_port));
uid5281789de9aa2003-10-23 18:42:24 +0000398 addr_buf += sizeof(struct sockaddr_in6);
399 }
400 }
401
402 sctp_freepaddrs(paddrs);
403
404 tst_resm(TPASS, "sctp_freepaddrs");
405
Simon Xu6f224942013-12-06 11:51:16 +0800406 /* Shut down the link. */
407 close(sk1);
uid5281789de9aa2003-10-23 18:42:24 +0000408
Simon Xu6f224942013-12-06 11:51:16 +0800409 /* Get the shutdown complete notification. */
uid5281789de9aa2003-10-23 18:42:24 +0000410 inmessage.msg_controllen = sizeof(incmsg);
411 inmessage.msg_namelen = sizeof(msgname);
412 memset(&msgname, 0, sizeof(msgname));
Simon Xu6f224942013-12-06 11:51:16 +0800413 error = test_recvmsg(sk2, &inmessage, MSG_WAITALL);
uid5281789de9aa2003-10-23 18:42:24 +0000414 test_check_msg_notification(&inmessage, error,
415 sizeof(struct sctp_assoc_change),
Simon Xu6f224942013-12-06 11:51:16 +0800416 SCTP_ASSOC_CHANGE, SCTP_SHUTDOWN_COMP);
uid5281789de9aa2003-10-23 18:42:24 +0000417#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 Xu6f224942013-12-06 11:51:16 +0800430 if (memcmp(&msgname.v6.sin6_addr, &in6addr_loopback,
uid5281789de9aa2003-10-23 18:42:24 +0000431 sizeof(msgname.v6.sin6_addr))) {
432 DUMP_CORE;
433 }
Simon Xu6f224942013-12-06 11:51:16 +0800434#else
uid5281789de9aa2003-10-23 18:42:24 +0000435 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 Xu6f224942013-12-06 11:51:16 +0800449
uid5281789de9aa2003-10-23 18:42:24 +0000450 tst_resm(TPASS, "recvmsg SHUTDOWN_COMP notification");
451
Simon Xu6f224942013-12-06 11:51:16 +0800452 close(sk2);
uid5281789de9aa2003-10-23 18:42:24 +0000453
Simon Xu6f224942013-12-06 11:51:16 +0800454 /* Indicate successful completion. */
455 return 0;
Chris Dearmanec6edca2012-10-17 19:54:01 -0700456}