Home | History | Annotate | Download | only in func_tests
      1 /* SCTP kernel Implementation
      2  * (C) Copyright IBM Corp. 2001, 2004
      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 <lksctp-developers (at) 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 (at) acm.org>
     37  *    Karl Knutson <karl (at) athena.chicago.il.us>
     38  *    Hui Huang <hui.huang (at) nokia.com>
     39  *    Jon Grimm <jgrimm (at) us.ibm.com>
     40  *    Sridhar Samudrala <samudrala (at) us.ibm.com>
     41  */
     42 
     43 /* This is a functional test to verify the various SCTP level socket
     44  * options that can be used to get information about existing SCTP
     45  * associations and to configure certain parameters.
     46  */
     47 
     48 #include <stdio.h>
     49 #include <unistd.h>
     50 #include <stdlib.h>
     51 #include <string.h>
     52 #include <sys/types.h>
     53 #include <sys/socket.h>
     54 #include <sys/uio.h>
     55 #include <sys/errno.h>
     56 #include <netinet/in.h>
     57 #include <netinet/sctp.h>
     58 #include <sctputil.h>
     59 
     60 char *TCID = __FILE__;
     61 int TST_TOTAL = 29;
     62 int TST_CNT = 0;
     63 
     64 int
     65 main(void)
     66 {
     67 	int udp_svr_sk, udp_clt_sk, tcp_svr_sk, tcp_clt_sk;
     68 	int accept_sk, peeloff_sk;
     69         sockaddr_storage_t udp_svr_loop, udp_clt_loop;
     70         sockaddr_storage_t tcp_svr_loop, tcp_clt_loop;
     71         struct iovec iov;
     72         struct msghdr inmessage;
     73 	struct msghdr outmessage;
     74 	char incmsg[CMSG_SPACE(sizeof(sctp_cmsg_data_t))];
     75 	char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
     76 	struct cmsghdr *cmsg;
     77 	struct sctp_sndrcvinfo *sinfo;
     78         struct iovec out_iov;
     79         char *message = "hello, world!\n";
     80         int error;
     81 	int pf_class;
     82 	uint32_t ppid;
     83 	uint32_t stream;
     84 	sctp_assoc_t udp_svr_associd, udp_clt_associd;
     85 	struct sctp_assoc_change *sac;
     86 	char *big_buffer;
     87 	struct sctp_event_subscribe subscribe;
     88 	struct sctp_initmsg initmsg;
     89 	struct sctp_paddrparams paddrparams;
     90 	struct sctp_sndrcvinfo set_udp_sk_dflt_param, get_udp_sk_dflt_param;
     91 	struct sctp_sndrcvinfo set_tcp_sk_dflt_param, get_tcp_sk_dflt_param;
     92 	struct sctp_sndrcvinfo set_udp_assoc_dflt_param;
     93 	struct sctp_sndrcvinfo get_udp_assoc_dflt_param;
     94 	struct sctp_sndrcvinfo set_tcp_assoc_dflt_param;
     95 	struct sctp_sndrcvinfo get_tcp_assoc_dflt_param;
     96 	struct sctp_sndrcvinfo get_peeloff_assoc_dflt_param;
     97 	struct sctp_sndrcvinfo get_accept_assoc_dflt_param;
     98 	struct sctp_paddrinfo pinfo;
     99 	int dflt_pathmaxrxt;
    100 	socklen_t optlen, addrlen;
    101 	struct sctp_status status;
    102 	struct sctp_assoc_value value;
    103 
    104         /* Rather than fflush() throughout the code, set stdout to
    105 	 * be unbuffered.
    106 	 */
    107 	setvbuf(stdout, NULL, _IONBF, 0);
    108 
    109 	/* Set some basic values which depend on the address family. */
    110 #if TEST_V6
    111 	pf_class = PF_INET6;
    112 
    113         udp_svr_loop.v6.sin6_family = AF_INET6;
    114         udp_svr_loop.v6.sin6_addr = in6addr_loopback;
    115         udp_svr_loop.v6.sin6_port = htons(SCTP_TESTPORT_1);
    116 
    117         udp_clt_loop.v6.sin6_family = AF_INET6;
    118         udp_clt_loop.v6.sin6_addr = in6addr_loopback;
    119         udp_clt_loop.v6.sin6_port = htons(SCTP_TESTPORT_1+1);
    120 
    121         tcp_svr_loop.v6.sin6_family = AF_INET6;
    122         tcp_svr_loop.v6.sin6_addr = in6addr_loopback;
    123         tcp_svr_loop.v6.sin6_port = htons(SCTP_TESTPORT_1+2);
    124 
    125         tcp_clt_loop.v6.sin6_family = AF_INET6;
    126         tcp_clt_loop.v6.sin6_addr = in6addr_loopback;
    127         tcp_clt_loop.v6.sin6_port = htons(SCTP_TESTPORT_1+3);
    128 #else
    129 	pf_class = PF_INET;
    130 
    131         udp_svr_loop.v4.sin_family = AF_INET;
    132         udp_svr_loop.v4.sin_addr.s_addr = SCTP_IP_LOOPBACK;
    133         udp_svr_loop.v4.sin_port = htons(SCTP_TESTPORT_1);
    134 
    135         udp_clt_loop.v4.sin_family = AF_INET;
    136         udp_clt_loop.v4.sin_addr.s_addr = SCTP_IP_LOOPBACK;
    137         udp_clt_loop.v4.sin_port = htons(SCTP_TESTPORT_1+1);
    138 
    139         tcp_svr_loop.v4.sin_family = AF_INET;
    140         tcp_svr_loop.v4.sin_addr.s_addr = SCTP_IP_LOOPBACK;
    141         tcp_svr_loop.v4.sin_port = htons(SCTP_TESTPORT_1+2);
    142 
    143         tcp_clt_loop.v4.sin_family = AF_INET;
    144         tcp_clt_loop.v4.sin_addr.s_addr = SCTP_IP_LOOPBACK;
    145         tcp_clt_loop.v4.sin_port = htons(SCTP_TESTPORT_2+3);
    146 #endif /* TEST_V6 */
    147 
    148         /* Create the two endpoints which will talk to each other.  */
    149         udp_svr_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    150         udp_clt_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    151 
    152 	/* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
    153 	test_enable_assoc_change(udp_svr_sk);
    154 	test_enable_assoc_change(udp_clt_sk);
    155 
    156         /* Bind these sockets to the test ports.  */
    157         test_bind(udp_svr_sk, &udp_svr_loop.sa, sizeof(udp_svr_loop));
    158         test_bind(udp_clt_sk, &udp_clt_loop.sa, sizeof(udp_clt_loop));
    159 
    160        /* Mark udp_svr_sk as being able to accept new associations.  */
    161 	test_listen(udp_svr_sk, 1);
    162 
    163 	/* TEST #1: SCTP_STATUS socket option. */
    164 	/* Make sure that SCTP_STATUS getsockopt on a socket with no
    165 	 * association fails.
    166 	 */
    167 	optlen = sizeof(struct sctp_status);
    168 	memset(&status, 0, optlen);
    169 	error = getsockopt(udp_svr_sk, SOL_SCTP, SCTP_STATUS, &status,
    170 			   &optlen);
    171 	if ((error != -1) && (errno != EINVAL))
    172 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_STATUS) on a "
    173 			 "socket with no assoc error:%d errno:%d",
    174 			 error, errno);
    175 
    176 	tst_resm(TPASS, "getsockopt(SCTP_STATUS) on a socket with no assoc");
    177 
    178         /* Send the first message.  This will create the association.  */
    179         outmessage.msg_name = &udp_svr_loop;
    180         outmessage.msg_namelen = sizeof(udp_svr_loop);
    181         outmessage.msg_iov = &out_iov;
    182         outmessage.msg_iovlen = 1;
    183         outmessage.msg_control = outcmsg;
    184         outmessage.msg_controllen = sizeof(outcmsg);
    185         outmessage.msg_flags = 0;
    186 	cmsg = CMSG_FIRSTHDR(&outmessage);
    187 	cmsg->cmsg_level = IPPROTO_SCTP;
    188 	cmsg->cmsg_type = SCTP_SNDRCV;
    189 	cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
    190 	outmessage.msg_controllen = cmsg->cmsg_len;
    191 	sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
    192 	memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo));
    193 	ppid = rand(); /* Choose an arbitrary value. */
    194 	stream = 1;
    195 	sinfo->sinfo_ppid = ppid;
    196 	sinfo->sinfo_stream = stream;
    197         outmessage.msg_iov->iov_base = message;
    198         outmessage.msg_iov->iov_len = strlen(message) + 1;
    199         test_sendmsg(udp_clt_sk, &outmessage, 0, strlen(message)+1);
    200 
    201 	/* Initialize inmessage for all receives. */
    202 	big_buffer = test_malloc(REALLY_BIG);
    203         memset(&inmessage, 0, sizeof(inmessage));
    204         iov.iov_base = big_buffer;
    205         iov.iov_len = REALLY_BIG;
    206         inmessage.msg_iov = &iov;
    207         inmessage.msg_iovlen = 1;
    208         inmessage.msg_control = incmsg;
    209 
    210         /* Get the communication up message on udp_svr_sk.  */
    211         inmessage.msg_controllen = sizeof(incmsg);
    212         error = test_recvmsg(udp_svr_sk, &inmessage, MSG_WAITALL);
    213 	test_check_msg_notification(&inmessage, error,
    214 				    sizeof(struct sctp_assoc_change),
    215 				    SCTP_ASSOC_CHANGE, SCTP_COMM_UP);
    216 	sac = (struct sctp_assoc_change *)iov.iov_base;
    217 	udp_svr_associd = sac->sac_assoc_id;
    218 
    219         /* Get the communication up message on udp_clt_sk.  */
    220         inmessage.msg_controllen = sizeof(incmsg);
    221         error = test_recvmsg(udp_clt_sk, &inmessage, MSG_WAITALL);
    222 	test_check_msg_notification(&inmessage, error,
    223 				    sizeof(struct sctp_assoc_change),
    224 				    SCTP_ASSOC_CHANGE, SCTP_COMM_UP);
    225 	sac = (struct sctp_assoc_change *)iov.iov_base;
    226 	udp_clt_associd = sac->sac_assoc_id;
    227 
    228         /* Get the first message which was sent.  */
    229         inmessage.msg_controllen = sizeof(incmsg);
    230         error = test_recvmsg(udp_svr_sk, &inmessage, MSG_WAITALL);
    231         test_check_msg_data(&inmessage, error, strlen(message) + 1,
    232 			    MSG_EOR, stream, ppid);
    233 
    234 	/* Get SCTP_STATUS for udp_clt_sk's given association. */
    235 	optlen = sizeof(struct sctp_status);
    236 	memset(&status, 0, optlen);
    237 	status.sstat_assoc_id = udp_clt_associd;
    238 	test_getsockopt(udp_clt_sk, SCTP_STATUS, &status, &optlen);
    239 
    240 	tst_resm(TPASS, "getsockopt(SCTP_STATUS)");
    241 
    242 	/* Make sure that SCTP_STATUS getsockopt with invalid associd fails. */
    243 	optlen = sizeof(struct sctp_status);
    244 	memset(&status, 0, optlen);
    245 	status.sstat_assoc_id = udp_svr_associd;
    246 	error = getsockopt(udp_clt_sk, SOL_SCTP, SCTP_STATUS, &status,
    247 			   &optlen);
    248 	if ((error != -1) && (errno != EINVAL))
    249         	tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_STATUS) with "
    250 			 "associd error: %d errno:%d", error, errno);
    251 
    252 	tst_resm(TPASS, "getsockopt(SCTP_STATUS) with invalid associd");
    253 
    254 	/* Make sure that SCTP_STATUS getsockopt with NULL associd fails. */
    255 	optlen = sizeof(struct sctp_status);
    256 	memset(&status, 0, optlen);
    257 	status.sstat_assoc_id = 0;
    258 	error = getsockopt(udp_svr_sk, SOL_SCTP, SCTP_STATUS, &status,
    259 			   &optlen);
    260 	if ((error != -1) && (errno != EINVAL))
    261         	tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_STATUS) with "
    262 			 "NULL associd error: %d errno:%d", error, errno);
    263 
    264 	tst_resm(TPASS, "getsockopt(SCTP_STATUS) with NULL associd");
    265 
    266         /* Shut down the link.  */
    267         close(udp_clt_sk);
    268 
    269         /* Get the shutdown complete notification. */
    270 	inmessage.msg_controllen = sizeof(incmsg);
    271         error = test_recvmsg(udp_svr_sk, &inmessage, MSG_WAITALL);
    272 	test_check_msg_notification(&inmessage, error,
    273 				    sizeof(struct sctp_assoc_change),
    274 				    SCTP_ASSOC_CHANGE, SCTP_SHUTDOWN_COMP);
    275 
    276 	error = 0;
    277         close(udp_svr_sk);
    278 
    279 	/* TEST #2: SCTP_EVENTS socket option and SCTP_SHUTDOWN_EVENT
    280 	 * notification.
    281 	 */
    282         /* Create the two endpoints which will talk to each other.  */
    283 	udp_svr_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    284 	udp_clt_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    285 
    286 	/* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
    287 	test_enable_assoc_change(udp_svr_sk);
    288 	test_enable_assoc_change(udp_clt_sk);
    289 
    290 	/* Bind these sockets to the test ports.  */
    291 	test_bind(udp_svr_sk, &udp_svr_loop.sa, sizeof(udp_svr_loop));
    292 	test_bind(udp_clt_sk, &udp_clt_loop.sa, sizeof(udp_clt_loop));
    293 
    294 	/* Mark udp_svr_sk as being able to accept new associations.  */
    295 	test_listen(udp_svr_sk, 1);
    296 
    297 	/* Get the default events that are enabled on udp_svr_sk. */
    298 	optlen = sizeof(subscribe);
    299 	test_getsockopt(udp_svr_sk, SCTP_EVENTS, &subscribe, &optlen);
    300 
    301 	/* Get the default events that are enabled on udp_clt_sk. */
    302 	optlen = sizeof(subscribe);
    303 	test_getsockopt(udp_clt_sk, SCTP_EVENTS, &subscribe, &optlen);
    304 
    305 	tst_resm(TPASS, "getsockopt(SCTP_EVENTS)");
    306 
    307 	/* Disable all the events on udp_svr_sk and udp_clt_sk. */
    308 	memset(&subscribe, 0, sizeof(struct sctp_event_subscribe));
    309 	test_setsockopt(udp_svr_sk, SCTP_EVENTS, &subscribe,
    310 			sizeof(subscribe));
    311 	test_setsockopt(udp_clt_sk, SCTP_EVENTS, &subscribe,
    312 			sizeof(subscribe));
    313 
    314 	tst_resm(TPASS, "setsockopt(SCTP_EVENTS)");
    315 
    316 	/* Get the updated list of enabled events on udp_svr_sk and
    317 	 * udp_clt_sk.
    318 	 */
    319 	optlen = sizeof(subscribe);
    320 	test_getsockopt(udp_svr_sk, SCTP_EVENTS, &subscribe, &optlen);
    321 	optlen = sizeof(subscribe);
    322 	test_getsockopt(udp_clt_sk, SCTP_EVENTS, &subscribe, &optlen);
    323 
    324 	/* Send a message.  This will create the association.  */
    325 	outmessage.msg_iov->iov_base = message;
    326 	outmessage.msg_iov->iov_len = strlen(message) + 1;
    327 	test_sendmsg(udp_clt_sk, &outmessage, 0, strlen(message)+1);
    328 
    329 	/* Get the message which was sent.  */
    330 	inmessage.msg_controllen = sizeof(incmsg);
    331 	error = test_recvmsg(udp_svr_sk, &inmessage, MSG_WAITALL);
    332         test_check_msg_data(&inmessage, error, strlen(message) + 1,
    333 			    MSG_EOR, 0, 0);
    334 	/* Verify that we received the msg without any ancillary data. */
    335 	if (inmessage.msg_controllen != 0)
    336 		tst_brkm(TBROK, tst_exit, "Receive unexpected ancillary"
    337 			 "data");
    338 
    339 	/* Enable SCTP_SHUTDOWN_EVENTs on udp_svr_sk. */
    340 	memset(&subscribe, 0, sizeof(struct sctp_event_subscribe));
    341 	subscribe.sctp_shutdown_event = 1;
    342 	test_setsockopt(udp_svr_sk, SCTP_EVENTS, &subscribe,
    343 			sizeof(subscribe));
    344 
    345 	error = 0;
    346         /* Shut down the link.  */
    347         close(udp_clt_sk);
    348 
    349 	/* Get the SHUTDOWN_EVENT notification on udp_svr_sk. */
    350 	inmessage.msg_controllen = sizeof(incmsg);
    351 	error = test_recvmsg(udp_svr_sk, &inmessage, MSG_WAITALL);
    352 	test_check_msg_notification(&inmessage, error,
    353 				    sizeof(struct sctp_shutdown_event),
    354 				    SCTP_SHUTDOWN_EVENT, 0);
    355 
    356 	tst_resm(TPASS, "setsockopt(SCTP_EVENTS) - SCTP_SHUTDOWN_EVENT");
    357 
    358         close(udp_svr_sk);
    359 
    360 	/* TEST #3: whether sctp_opt_info equals */
    361         /* Create the two endpoints which will talk to each other.  */
    362 	udp_svr_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    363 	udp_clt_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    364 
    365 	/* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
    366 	test_enable_assoc_change(udp_svr_sk);
    367 	test_enable_assoc_change(udp_clt_sk);
    368 
    369 	/* Bind these sockets to the test ports.  */
    370 	test_bind(udp_svr_sk, &udp_svr_loop.sa, sizeof(udp_svr_loop));
    371 	test_bind(udp_clt_sk, &udp_clt_loop.sa, sizeof(udp_clt_loop));
    372 
    373 	/* Mark udp_svr_sk as being able to accept new associations.  */
    374 	test_listen(udp_svr_sk, 1);
    375 
    376         /* Send the first message.  This will create the association.  */
    377         outmessage.msg_name = &udp_svr_loop;
    378         outmessage.msg_namelen = sizeof(udp_svr_loop);
    379         outmessage.msg_iov = &out_iov;
    380         outmessage.msg_iovlen = 1;
    381         outmessage.msg_control = outcmsg;
    382         outmessage.msg_controllen = sizeof(outcmsg);
    383         outmessage.msg_flags = 0;
    384 	cmsg = CMSG_FIRSTHDR(&outmessage);
    385 	cmsg->cmsg_level = IPPROTO_SCTP;
    386 	cmsg->cmsg_type = SCTP_SNDRCV;
    387 	cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));
    388 	outmessage.msg_controllen = cmsg->cmsg_len;
    389 	sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
    390 	memset(sinfo, 0x00, sizeof(struct sctp_sndrcvinfo));
    391 	ppid = rand(); /* Choose an arbitrary value. */
    392 	stream = 1;
    393 	sinfo->sinfo_ppid = ppid;
    394 	sinfo->sinfo_stream = stream;
    395         outmessage.msg_iov->iov_base = message;
    396         outmessage.msg_iov->iov_len = strlen(message) + 1;
    397         test_sendmsg(udp_clt_sk, &outmessage, 0, strlen(message)+1);
    398 
    399         /* Get the communication up message on udp_clt_sk.  */
    400         inmessage.msg_controllen = sizeof(incmsg);
    401         error = test_recvmsg(udp_clt_sk, &inmessage, MSG_WAITALL);
    402 	test_check_msg_notification(&inmessage, error,
    403 				    sizeof(struct sctp_assoc_change),
    404 				    SCTP_ASSOC_CHANGE, SCTP_COMM_UP);
    405 	sac = (struct sctp_assoc_change *)iov.iov_base;
    406 	udp_clt_associd = sac->sac_assoc_id;
    407 
    408 	/* Compare the SCTP_STATUS result between sctp_opt_info and
    409 	 * getsockopt
    410 	 */
    411 	{
    412 		struct sctp_status status1, status2;
    413 
    414 		memset(&status1, 0, sizeof(status1));
    415 		memset(&status2, 0, sizeof(status2));
    416 		optlen = sizeof(struct sctp_status);
    417 
    418 		/* Test SCTP_STATUS for udp_clt_sk's given association. */
    419 		error = sctp_opt_info(udp_clt_sk,udp_clt_associd,SCTP_STATUS,
    420 				(char *)&status1, &optlen);
    421 		if (error != 0)
    422 	                tst_brkm(TBROK, tst_exit,
    423 				 "sctp_opt_info(SCTP_STATUS): %s",
    424 				 strerror(errno));
    425 
    426 		status2.sstat_assoc_id = udp_clt_associd;
    427 		error = getsockopt(udp_clt_sk, IPPROTO_SCTP, SCTP_STATUS,
    428                 		(char *)&status2, &optlen);
    429 		if (error != 0)
    430 	                tst_brkm(TBROK, tst_exit,
    431 				 "getsockopt(SCTP_STATUS): %s",
    432 				 strerror(errno));
    433 		if (strncmp((char *)&status1, (char *)&status2, optlen))
    434 	                tst_brkm(TBROK, tst_exit, "sctp_opt_info(SCTP_STAUS)"
    435 			       "doesn't match getsockopt(SCTP_STATUS)");
    436 
    437                 tst_resm(TPASS, "sctp_opt_info(SCTP_STATUS)");
    438 	}
    439 	error = 0;
    440         /* Shut down the link.  */
    441         close(udp_svr_sk);
    442         close(udp_clt_sk);
    443 
    444 	/* TEST #4: SCTP_INITMSG socket option. */
    445         /* Create a socket.  */
    446 	udp_svr_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    447 
    448 	/* Bind this socket to the test port.  */
    449 	test_bind(udp_svr_sk, &udp_svr_loop.sa, sizeof(udp_svr_loop));
    450 
    451 	/* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
    452 	test_enable_assoc_change(udp_svr_sk);
    453 
    454 	/* Get the default parameters for association initialization. */
    455 	optlen = sizeof(initmsg);
    456 	test_getsockopt(udp_svr_sk, SCTP_INITMSG, &initmsg, &optlen);
    457 
    458 	tst_resm(TPASS, "getsockopt(SCTP_INITMSG)");
    459 
    460 	/* Change the parameters for association initialization. */
    461 	initmsg.sinit_num_ostreams = 5;
    462 	initmsg.sinit_max_instreams = 5;
    463 	initmsg.sinit_max_attempts = 3;
    464 	initmsg.sinit_max_init_timeo = 30;
    465 	test_setsockopt(udp_svr_sk, SCTP_INITMSG, &initmsg, sizeof(initmsg));
    466 
    467 	tst_resm(TPASS, "setsockopt(SCTP_INITMSG)");
    468 
    469 	/* Get the updated parameters for association initialization. */
    470 	optlen = sizeof(initmsg);
    471 	test_getsockopt(udp_svr_sk, SCTP_INITMSG, &initmsg, &optlen);
    472 
    473 	close(udp_svr_sk);
    474 
    475 	/* TEST #5: SCTP_PEER_ADDR_PARAMS socket option. */
    476         /* Create a socket.  */
    477 	udp_svr_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    478 
    479 	/* Get the default parameters for this endpoint */
    480 	optlen = sizeof(paddrparams);
    481 	memset(&paddrparams, 0, sizeof(paddrparams));
    482 	paddrparams.spp_address.ss_family = AF_INET;
    483 	test_getsockopt(udp_svr_sk, SCTP_PEER_ADDR_PARAMS, &paddrparams,
    484 								&optlen);
    485 
    486 	dflt_pathmaxrxt = paddrparams.spp_pathmaxrxt;
    487 	tst_resm(TPASS, "getsockopt(SCTP_PEER_ADDR_PARAMS)");
    488 
    489 	/* Change the default parameters for this endpoint (socket) */
    490 	paddrparams.spp_hbinterval = 1000;
    491 	paddrparams.spp_pathmaxrxt = dflt_pathmaxrxt+1;
    492 	paddrparams.spp_sackdelay = 100;
    493 	test_setsockopt(udp_svr_sk, SCTP_PEER_ADDR_PARAMS, &paddrparams,
    494 							sizeof(paddrparams));
    495 
    496 	paddrparams.spp_pathmaxrxt = 0;
    497 
    498 	/* Get the updated default parameters for this endpoint. */
    499 	optlen = sizeof(paddrparams);
    500 	test_getsockopt(udp_svr_sk, SCTP_PEER_ADDR_PARAMS, &paddrparams,
    501 								&optlen);
    502 	if (paddrparams.spp_pathmaxrxt != dflt_pathmaxrxt+1)
    503 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    504 			 "mismatch");
    505 
    506 	value.assoc_id = 0;
    507 	optlen = sizeof(value);
    508 	test_getsockopt(udp_svr_sk, SCTP_DELAYED_ACK_TIME, &value,
    509 								&optlen);
    510 	if (value.assoc_value != 100)
    511 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DELAYED_ACK_TIME) "
    512 			 "mismatch");
    513 
    514 	value.assoc_id    = 0;
    515 	value.assoc_value = 250;
    516 	test_setsockopt(udp_svr_sk, SCTP_DELAYED_ACK_TIME, &value,
    517 							sizeof(value));
    518 	optlen = sizeof(paddrparams);
    519 	test_getsockopt(udp_svr_sk, SCTP_PEER_ADDR_PARAMS, &paddrparams,
    520 								&optlen);
    521 	if (paddrparams.spp_sackdelay != 250)
    522 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_DELAYED_ACK_TIME) "
    523 			 "mismatch");
    524 
    525 	tst_resm(TPASS, "setsockopt(SCTP_DELAYED_ACK_TIME)");
    526 
    527 
    528 	/* Ensure that prior defaults are preserved for a new endpoint */
    529 	udp_clt_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    530 	optlen = sizeof(paddrparams);
    531 	memset(&paddrparams, 0, sizeof(paddrparams));
    532 	paddrparams.spp_address.ss_family = AF_INET;
    533 	test_getsockopt(udp_clt_sk, SCTP_PEER_ADDR_PARAMS, &paddrparams,
    534 								&optlen);
    535 	if (paddrparams.spp_pathmaxrxt != dflt_pathmaxrxt)
    536 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_PEER_ADDR_PARAMS) "
    537 			 "mismatch");
    538 
    539 
    540 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS)");
    541 
    542        	/* Invalid assoc id */
    543 	paddrparams.spp_assoc_id = 1234;
    544         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_PEER_ADDR_PARAMS,
    545 			   &paddrparams,
    546 			   sizeof(paddrparams));
    547 	if ((-1 != error) || (EINVAL != errno))
    548 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    549 			 "invalid associd error:%d, errno:%d\n",
    550 			 error, errno);
    551 
    552 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    553 		 "- one-to-many style invalid associd");
    554 
    555 	test_bind(udp_svr_sk, &udp_svr_loop.sa, sizeof(udp_svr_loop));
    556 	test_bind(udp_clt_sk, &udp_clt_loop.sa, sizeof(udp_clt_loop));
    557 
    558 	test_listen(udp_svr_sk, 5);
    559 
    560 	test_enable_assoc_change(udp_svr_sk);
    561 	test_enable_assoc_change(udp_clt_sk);
    562 
    563 	/* Do a connect on a UDP-style socket and establish an association. */
    564 	test_connect(udp_clt_sk, &udp_svr_loop.sa, sizeof(udp_svr_loop));
    565 
    566 	/* Receive the COMM_UP notifications and get the associd's */
    567 	inmessage.msg_controllen = sizeof(incmsg);
    568 	error = test_recvmsg(udp_svr_sk, &inmessage, MSG_WAITALL);
    569 	test_check_msg_notification(&inmessage, error,
    570 				    sizeof(struct sctp_assoc_change),
    571 				    SCTP_ASSOC_CHANGE, SCTP_COMM_UP);
    572 	sac = (struct sctp_assoc_change *)iov.iov_base;
    573 
    574 	paddrparams.spp_assoc_id = sac->sac_assoc_id;
    575 	memcpy(&paddrparams.spp_address, &udp_clt_loop, sizeof(udp_clt_loop));
    576 	paddrparams.spp_hbinterval = 1000;
    577 	paddrparams.spp_pathmaxrxt = dflt_pathmaxrxt+1;
    578 	test_setsockopt(udp_svr_sk, SCTP_PEER_ADDR_PARAMS, &paddrparams,
    579 							sizeof(paddrparams));
    580 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) - "
    581 		 "one-to-many style valid associd valid address");
    582 
    583 	paddrparams.spp_assoc_id = sac->sac_assoc_id;
    584 	memcpy(&paddrparams.spp_address, &udp_svr_loop, sizeof(udp_svr_loop));
    585 	paddrparams.spp_hbinterval = 1000;
    586 	paddrparams.spp_pathmaxrxt = dflt_pathmaxrxt+1;
    587 
    588         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_PEER_ADDR_PARAMS,
    589 			   &paddrparams,
    590 			   sizeof(paddrparams));
    591 	if ((-1 != error) || (EINVAL != errno))
    592 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    593 			 "invalid transport error:%d, errno:%d\n",
    594 			 error, errno);
    595 
    596 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    597 		 "- one-to-many style invalid transport");
    598 
    599 	paddrparams.spp_assoc_id = sac->sac_assoc_id;
    600 	memcpy(&paddrparams.spp_address, &udp_clt_loop, sizeof(udp_clt_loop));
    601 	paddrparams.spp_hbinterval = 1000;
    602 	paddrparams.spp_pathmaxrxt = dflt_pathmaxrxt+1;
    603 
    604         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_PEER_ADDR_PARAMS,
    605 			   &paddrparams,
    606 			   sizeof(paddrparams) - 1);
    607 	if ((-1 != error) || (EINVAL != errno))
    608 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    609 			 "invalid parameter length error:%d, errno:%d\n",
    610 			 error, errno);
    611 
    612 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    613 		 "- one-to-many style invalid parameter length");
    614 
    615         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_DELAYED_ACK_TIME,
    616 			   &value,
    617 			   sizeof(value) - 1);
    618 	if ((-1 != error) || (EINVAL != errno))
    619 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_DELAYED_ACK_TIME) "
    620 			 "invalid parameter length error:%d, errno:%d\n",
    621 			 error, errno);
    622 
    623 	tst_resm(TPASS, "setsockopt(SCTP_DELAYED_ACK_TIME) "
    624 		 "- one-to-many style invalid parameter length");
    625 
    626 	memset(&paddrparams, 0, sizeof(paddrparams));
    627 	paddrparams.spp_assoc_id = sac->sac_assoc_id;
    628 	memcpy(&paddrparams.spp_address, &udp_clt_loop, sizeof(udp_clt_loop));
    629 	paddrparams.spp_sackdelay = 501;
    630 
    631         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_PEER_ADDR_PARAMS,
    632 			   &paddrparams,
    633 			   sizeof(paddrparams));
    634 	if ((-1 != error) || (EINVAL != errno))
    635 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    636 			 "invalid sack delay error:%d, errno:%d\n",
    637 			 error, errno);
    638 
    639 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    640 		 "- one-to-many style invalid sack delay");
    641 
    642 	value.assoc_id    = sac->sac_assoc_id;
    643 	value.assoc_value = 501;
    644 
    645         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_DELAYED_ACK_TIME,
    646 			   &value,
    647 			   sizeof(value));
    648 	if ((-1 != error) || (EINVAL != errno))
    649 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_DELAYED_ACK_TIME) "
    650 			 "invalid sack delay error:%d, errno:%d\n",
    651 			 error, errno);
    652 
    653 	tst_resm(TPASS, "setsockopt(SCTP_DELAYED_ACK_TIME) "
    654 		 "- one-to-many style invalid sack delay");
    655 
    656 	memset(&paddrparams, 0, sizeof(paddrparams));
    657 	paddrparams.spp_assoc_id = sac->sac_assoc_id;
    658 	memcpy(&paddrparams.spp_address, &udp_clt_loop, sizeof(udp_clt_loop));
    659 	paddrparams.spp_pathmtu = 511;
    660 
    661         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_PEER_ADDR_PARAMS,
    662 			   &paddrparams,
    663 			   sizeof(paddrparams));
    664 	if ((-1 != error) || (EINVAL != errno))
    665 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    666 			 "invalid path MTU error:%d, errno:%d\n",
    667 			 error, errno);
    668 
    669 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    670 		 "- one-to-many style invalid path MTU");
    671 
    672 	memset(&paddrparams, 0, sizeof(paddrparams));
    673 	paddrparams.spp_assoc_id = sac->sac_assoc_id;
    674 	memcpy(&paddrparams.spp_address, &udp_clt_loop, sizeof(udp_clt_loop));
    675 	paddrparams.spp_flags = SPP_HB_ENABLE | SPP_HB_DISABLE;
    676 
    677         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_PEER_ADDR_PARAMS,
    678 			   &paddrparams,
    679 			   sizeof(paddrparams));
    680 	if ((-1 != error) || (EINVAL != errno))
    681 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    682 			 "invalid hb enable flags error:%d, errno:%d\n",
    683 			 error, errno);
    684 
    685 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    686 		 "- one-to-many style invalid hb enable flags");
    687 
    688 	memset(&paddrparams, 0, sizeof(paddrparams));
    689 	paddrparams.spp_assoc_id = sac->sac_assoc_id;
    690 	memcpy(&paddrparams.spp_address, &udp_clt_loop, sizeof(udp_clt_loop));
    691 	paddrparams.spp_flags = SPP_PMTUD_ENABLE | SPP_PMTUD_DISABLE;
    692 
    693         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_PEER_ADDR_PARAMS,
    694 			   &paddrparams,
    695 			   sizeof(paddrparams));
    696 	if ((-1 != error) || (EINVAL != errno))
    697 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    698 			 "invalid PMTU discovery enable flags error:%d, errno:%d\n",
    699 			 error, errno);
    700 
    701 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    702 		 "- one-to-many style invalid PMTU discovery enable flags");
    703 
    704 	memset(&paddrparams, 0, sizeof(paddrparams));
    705 	paddrparams.spp_assoc_id = sac->sac_assoc_id;
    706 	memcpy(&paddrparams.spp_address, &udp_clt_loop, sizeof(udp_clt_loop));
    707 	paddrparams.spp_flags = SPP_SACKDELAY_ENABLE | SPP_SACKDELAY_DISABLE;
    708 
    709         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_PEER_ADDR_PARAMS,
    710 			   &paddrparams,
    711 			   sizeof(paddrparams));
    712 	if ((-1 != error) || (EINVAL != errno))
    713 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    714 			 "invalid sack delay enable flags error:%d, errno:%d\n",
    715 			 error, errno);
    716 
    717 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    718 		 "- one-to-many style invalid sack delay enable flags");
    719 
    720 	memset(&paddrparams, 0, sizeof(paddrparams));
    721 	paddrparams.spp_flags = SPP_HB_DEMAND;
    722 
    723         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_PEER_ADDR_PARAMS,
    724 			   &paddrparams,
    725 			   sizeof(paddrparams));
    726 	if ((-1 != error) || (EINVAL != errno))
    727 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    728 			 "invalid hb demand error:%d, errno:%d\n",
    729 			 error, errno);
    730 
    731 	tst_resm(TPASS, "setsockopt(SCTP_PEER_ADDR_PARAMS) "
    732 		 "- one-to-many style invalid hb demand");
    733 
    734 	close(udp_svr_sk);
    735 	close(udp_clt_sk);
    736 
    737 
    738 	/* TEST #6: SCTP_DEFAULT_SEND_PARAM socket option. */
    739 	/* Create and bind 2 UDP-style sockets(udp_svr_sk, udp_clt_sk) and
    740 	 * 2 TCP-style sockets. (tcp_svr_sk, tcp_clt_sk)
    741 	 */
    742 	udp_svr_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    743 	udp_clt_sk = test_socket(pf_class, SOCK_SEQPACKET, IPPROTO_SCTP);
    744 	tcp_svr_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
    745 	tcp_clt_sk = test_socket(pf_class, SOCK_STREAM, IPPROTO_SCTP);
    746 
    747 	/* Enable ASSOC_CHANGE and SNDRCVINFO notifications. */
    748 	test_enable_assoc_change(udp_svr_sk);
    749 	test_enable_assoc_change(udp_clt_sk);
    750 	test_enable_assoc_change(tcp_svr_sk);
    751 	test_enable_assoc_change(tcp_clt_sk);
    752 
    753 	test_bind(udp_svr_sk, &udp_svr_loop.sa, sizeof(udp_svr_loop));
    754 	test_bind(udp_clt_sk, &udp_clt_loop.sa, sizeof(udp_clt_loop));
    755 	test_bind(tcp_svr_sk, &tcp_svr_loop.sa, sizeof(tcp_svr_loop));
    756 	test_bind(tcp_clt_sk, &tcp_clt_loop.sa, sizeof(tcp_clt_loop));
    757 
    758 	/* Mark udp_svr_sk and tcp_svr_sk as being able to accept new
    759 	 * associations.
    760 	 */
    761 	test_listen(udp_svr_sk, 5);
    762 	test_listen(tcp_svr_sk, 5);
    763 
    764 	/* Set default send parameters on the unconnected UDP-style sockets. */
    765 	memset(&set_udp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    766 	set_udp_sk_dflt_param.sinfo_ppid = 1000;
    767 	test_setsockopt(udp_svr_sk, SCTP_DEFAULT_SEND_PARAM,
    768 			&set_udp_sk_dflt_param, sizeof(set_udp_sk_dflt_param));
    769 	memset(&set_udp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    770 	set_udp_sk_dflt_param.sinfo_ppid = 1000;
    771 	test_setsockopt(udp_clt_sk, SCTP_DEFAULT_SEND_PARAM,
    772 			&set_udp_sk_dflt_param, sizeof(set_udp_sk_dflt_param));
    773 
    774 	tst_resm(TPASS, "setsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    775 		 "one-to-many style socket");
    776 
    777 	/* Get default send parameters on the unconnected UDP-style socket. */
    778 	memset(&get_udp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    779 	optlen = sizeof(get_udp_sk_dflt_param);
    780 	test_getsockopt(udp_svr_sk, SCTP_DEFAULT_SEND_PARAM,
    781 			&get_udp_sk_dflt_param, &optlen);
    782 
    783 	/* Verify that the get param matches set param. */
    784 	if (set_udp_sk_dflt_param.sinfo_ppid !=
    785 			get_udp_sk_dflt_param.sinfo_ppid)
    786 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
    787 			 "mismatch.");
    788 
    789 	/* Get default send parameters on the unconnected UDP-style socket. */
    790 	memset(&get_udp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    791 	optlen = sizeof(get_udp_sk_dflt_param);
    792 	test_getsockopt(udp_clt_sk, SCTP_DEFAULT_SEND_PARAM,
    793 		       &get_udp_sk_dflt_param, &optlen);
    794 
    795 	/* Verify that the get param matches set param. */
    796 	if (set_udp_sk_dflt_param.sinfo_ppid !=
    797 			get_udp_sk_dflt_param.sinfo_ppid)
    798 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
    799 			 "mismatch.");
    800 
    801 	tst_resm(TPASS, "getsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    802 		 "one-to-many style socket");
    803 
    804 	/* Verify that trying to set send params with an invalid assoc id
    805 	 * on an UDP-style socket fails.
    806 	 */
    807 	memset(&set_udp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    808 	set_udp_sk_dflt_param.sinfo_ppid = 1000;
    809        	/* Invalid assoc id */
    810 	set_udp_sk_dflt_param.sinfo_assoc_id = 1234;
    811         error = setsockopt(udp_clt_sk, SOL_SCTP, SCTP_DEFAULT_SEND_PARAM,
    812 			   &set_udp_sk_dflt_param,
    813 			   sizeof(set_udp_sk_dflt_param));
    814 	if ((-1 != error) || (EINVAL != errno))
    815 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_DEFAULT_SEND_PARAM) "
    816 			 "invalid associd error:%d, errno:%d\n",
    817 			 error, errno);
    818 
    819 	tst_resm(TPASS, "setsockopt(SCTP_DEFAULT_SEND_PARAM) "
    820 		 "- one-to-many style invalid associd");
    821 
    822 	/* Do a connect on a UDP-style socket and establish an association. */
    823 	test_connect(udp_clt_sk, &udp_svr_loop.sa, sizeof(udp_svr_loop));
    824 
    825 	/* Receive the COMM_UP notifications and get the associd's */
    826 	inmessage.msg_controllen = sizeof(incmsg);
    827 	error = test_recvmsg(udp_svr_sk, &inmessage, MSG_WAITALL);
    828 	test_check_msg_notification(&inmessage, error,
    829 				    sizeof(struct sctp_assoc_change),
    830 				    SCTP_ASSOC_CHANGE, SCTP_COMM_UP);
    831 	sac = (struct sctp_assoc_change *)iov.iov_base;
    832 	udp_svr_associd = sac->sac_assoc_id;
    833 
    834 	inmessage.msg_controllen = sizeof(incmsg);
    835 	error = test_recvmsg(udp_clt_sk, &inmessage, MSG_WAITALL);
    836 	test_check_msg_notification(&inmessage, error,
    837 				    sizeof(struct sctp_assoc_change),
    838 				    SCTP_ASSOC_CHANGE, SCTP_COMM_UP);
    839 	sac = (struct sctp_assoc_change *)iov.iov_base;
    840 	udp_clt_associd = sac->sac_assoc_id;
    841 
    842 	/* Verify that trying to set send params with an assoc id not
    843 	 * belonging to the socket on an UDP-style socket fails.
    844 	 */
    845 	memset(&set_udp_assoc_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    846 	set_udp_assoc_dflt_param.sinfo_ppid = 3000;
    847 	set_udp_assoc_dflt_param.sinfo_assoc_id = udp_clt_associd;
    848 	error = setsockopt(udp_svr_sk, SOL_SCTP, SCTP_DEFAULT_SEND_PARAM,
    849 			   &set_udp_assoc_dflt_param,
    850 			   sizeof(set_udp_assoc_dflt_param));
    851 	if ((-1 != error) || (EINVAL != errno))
    852 		tst_brkm(TBROK, tst_exit, "setsockopt(SCTP_DEFAULT_SEND_PARAM) "
    853 			 "associd belonging to another socket "
    854 			 "error:%d, errno:%d", error, errno);
    855 
    856 	tst_resm(TPASS, "setsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    857 		 "one-to-many style associd belonging to another socket");
    858 
    859 	/* Set default send parameters of an association on the listening
    860 	 * UDP-style socket with a valid associd.
    861 	 */
    862 	memset(&set_udp_assoc_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    863 	set_udp_assoc_dflt_param.sinfo_ppid = 3000;
    864 	set_udp_assoc_dflt_param.sinfo_assoc_id = udp_svr_associd;
    865 	test_setsockopt(udp_svr_sk, SCTP_DEFAULT_SEND_PARAM,
    866 			&set_udp_assoc_dflt_param,
    867 			sizeof(set_udp_assoc_dflt_param));
    868 
    869 	tst_resm(TPASS, "setsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    870 		 "one-to-many style valid associd");
    871 
    872 	/* Get default send parameters of an association on the listening
    873 	 * UDP-style socket with a valid associd.
    874 	 */
    875 	memset(&get_udp_assoc_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    876 	get_udp_assoc_dflt_param.sinfo_assoc_id = udp_svr_associd ;
    877 	optlen = sizeof(get_udp_assoc_dflt_param);
    878 	test_getsockopt(udp_svr_sk, SCTP_DEFAULT_SEND_PARAM,
    879 			&get_udp_assoc_dflt_param, &optlen);
    880 
    881 	/* Verify that the get param matches the set param. */
    882 	if (get_udp_assoc_dflt_param.sinfo_ppid !=
    883 			set_udp_assoc_dflt_param.sinfo_ppid)
    884 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
    885 			 "mismatch.");
    886 
    887 	tst_resm(TPASS, "getsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    888 		 "one-to-many style valid associd");
    889 
    890 	/* Get default send parameters of an association on the connected
    891 	 * UDP-style socket with zero associd. This should return the
    892 	 * socket wide default parameters.
    893 	 */
    894 	memset(&get_udp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    895 	get_udp_sk_dflt_param.sinfo_assoc_id = 0 ;
    896 	optlen = sizeof(get_udp_sk_dflt_param);
    897 	test_getsockopt(udp_clt_sk, SCTP_DEFAULT_SEND_PARAM,
    898 			&get_udp_sk_dflt_param, &optlen);
    899 
    900 	/* Verify that the get param matches the socket-wide set param. */
    901 	if (get_udp_sk_dflt_param.sinfo_ppid !=
    902 			set_udp_sk_dflt_param.sinfo_ppid)
    903 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
    904 			 "mismatch.");
    905 
    906 	tst_resm(TPASS, "getsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    907 		 "one-to-many style zero associd");
    908 
    909 	peeloff_sk = test_sctp_peeloff(udp_svr_sk, udp_svr_associd);
    910 
    911 	/* Get default send parameters of an association on the peeled off
    912 	 * UDP-style socket. This should return the association's default
    913 	 * parameters.
    914 	 */
    915 	memset(&get_peeloff_assoc_dflt_param, 0,
    916 	       sizeof(struct sctp_sndrcvinfo));
    917 	get_peeloff_assoc_dflt_param.sinfo_assoc_id = 0 ;
    918 	optlen = sizeof(get_peeloff_assoc_dflt_param);
    919 	test_getsockopt(peeloff_sk, SCTP_DEFAULT_SEND_PARAM,
    920 			&get_peeloff_assoc_dflt_param, &optlen);
    921 
    922 	/* Verify that the get param matches the association's set param. */
    923 	if (get_peeloff_assoc_dflt_param.sinfo_ppid !=
    924 			set_udp_assoc_dflt_param.sinfo_ppid)
    925 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
    926 			 "mismatch.");
    927 
    928 	tst_resm(TPASS, "getsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    929 		 "one-to-many style peeled off socket");
    930 
    931 	/* Set default send parameters on the unconnected TCP-style sockets. */
    932 	memset(&set_tcp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    933 	set_tcp_sk_dflt_param.sinfo_ppid = 2000;
    934 	/* Invalid assoc id, ignored on a TCP-style socket. */
    935 	set_tcp_sk_dflt_param.sinfo_assoc_id = 1234;
    936 	test_setsockopt(tcp_svr_sk, SCTP_DEFAULT_SEND_PARAM,
    937 			&set_tcp_sk_dflt_param,
    938 			sizeof(set_tcp_sk_dflt_param));
    939 
    940 	/* Set default send parameters on the unconnected TCP-style sockets. */
    941 	memset(&set_tcp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    942 	set_tcp_sk_dflt_param.sinfo_ppid = 2000;
    943 	/* Invalid assoc id, ignored on a TCP-style socket. */
    944 	set_tcp_sk_dflt_param.sinfo_assoc_id = 1234;
    945 	test_setsockopt(tcp_clt_sk, SCTP_DEFAULT_SEND_PARAM,
    946 			&set_tcp_sk_dflt_param,
    947 			sizeof(set_tcp_sk_dflt_param));
    948 
    949 	tst_resm(TPASS, "setsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    950 		 "one-to-one style socket");
    951 
    952 	/* Get default send parameters on the unconnected TCP-style socket. */
    953 	memset(&get_tcp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    954 	optlen = sizeof(get_tcp_sk_dflt_param);
    955 	test_getsockopt(tcp_svr_sk, SCTP_DEFAULT_SEND_PARAM,
    956 			&get_tcp_sk_dflt_param, &optlen);
    957 
    958 	/* Verify that the get param matches set param. */
    959 	if (set_tcp_sk_dflt_param.sinfo_ppid !=
    960 			get_tcp_sk_dflt_param.sinfo_ppid)
    961 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
    962 			 "mismatch.");
    963 
    964 	/* Get default send parameters on the unconnected TCP-style socket. */
    965 	memset(&get_tcp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    966 	optlen = sizeof(get_tcp_sk_dflt_param);
    967 	test_getsockopt(tcp_clt_sk, SCTP_DEFAULT_SEND_PARAM,
    968 			&get_tcp_sk_dflt_param, &optlen);
    969 
    970 	/* Verify that the get param matches set param. */
    971 	if (set_tcp_sk_dflt_param.sinfo_ppid !=
    972 			get_tcp_sk_dflt_param.sinfo_ppid)
    973 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
    974 			 "mismatch.");
    975 
    976 	tst_resm(TPASS, "getsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    977 		 "one-to-one style socket");
    978 
    979 	/* Do a connect on a TCP-style socket and establish an association. */
    980 	test_connect(tcp_clt_sk, &tcp_svr_loop.sa, sizeof(tcp_svr_loop));
    981 
    982 	/* Set default send parameters of an association on the connected
    983 	 * TCP-style socket.
    984 	 */
    985 	memset(&set_tcp_assoc_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    986 	set_tcp_assoc_dflt_param.sinfo_ppid = 4000;
    987 	set_tcp_assoc_dflt_param.sinfo_assoc_id = 0;
    988 	test_setsockopt(tcp_clt_sk, SCTP_DEFAULT_SEND_PARAM,
    989 			&set_tcp_assoc_dflt_param,
    990 			sizeof(set_tcp_assoc_dflt_param));
    991 
    992 	tst_resm(TPASS, "setsockopt(SCTP_DEFAULT_SEND_PARAM) - "
    993 		 "one-to-one style assoc");
    994 
    995 	/* Get default send parameters of an association on the connected
    996 	 * TCP-style socket.
    997 	 */
    998 	memset(&get_tcp_assoc_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
    999 	optlen = sizeof(get_tcp_assoc_dflt_param);
   1000 	test_getsockopt(tcp_clt_sk, SCTP_DEFAULT_SEND_PARAM,
   1001 			&get_tcp_assoc_dflt_param, &optlen);
   1002 
   1003 	if (set_tcp_assoc_dflt_param.sinfo_ppid !=
   1004 			get_tcp_assoc_dflt_param.sinfo_ppid)
   1005 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
   1006 			 "mismatch.");
   1007 
   1008 	/* Get default send parameters on the connected TCP-style socket.  */
   1009 	memset(&get_tcp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
   1010 	optlen = sizeof(get_tcp_sk_dflt_param);
   1011 	test_getsockopt(tcp_clt_sk, SCTP_DEFAULT_SEND_PARAM,
   1012 			&get_tcp_sk_dflt_param, &optlen);
   1013 
   1014 	/* Verify that the get parameters returned matches the set param
   1015 	 * set for the association, not the socket-wide param.
   1016 	 */
   1017 	if ((get_tcp_sk_dflt_param.sinfo_ppid ==
   1018 			set_tcp_sk_dflt_param.sinfo_ppid) ||
   1019 	    (get_tcp_sk_dflt_param.sinfo_ppid !=
   1020 	    		set_tcp_assoc_dflt_param.sinfo_ppid))
   1021 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
   1022 			 "mismatch.");
   1023 
   1024 	/* Get default send parameters on the listening TCP-style socket.  */
   1025 	memset(&get_tcp_sk_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
   1026 	optlen = sizeof(get_tcp_sk_dflt_param);
   1027 	test_getsockopt(tcp_svr_sk, SCTP_DEFAULT_SEND_PARAM,
   1028 			&get_tcp_sk_dflt_param, &optlen);
   1029 
   1030 	/* Verify that the get parameters returned matches the socket-wide
   1031 	 * set param.
   1032 	 */
   1033 	if (get_tcp_sk_dflt_param.sinfo_ppid !=
   1034 			set_tcp_sk_dflt_param.sinfo_ppid)
   1035 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
   1036 			 "mismatch.");
   1037 
   1038 	tst_resm(TPASS, "getsockopt(SCTP_DEFAULT_SEND_PARAM) - "
   1039 		 "one-to-one style assoc");
   1040 
   1041 	accept_sk = test_accept(tcp_svr_sk, NULL, &addrlen);
   1042 
   1043 	/* Get default send parameters of an association on the accepted
   1044 	 * TCP-style socket.
   1045 	 */
   1046 	memset(&get_accept_assoc_dflt_param, 0, sizeof(struct sctp_sndrcvinfo));
   1047 	optlen = sizeof(get_accept_assoc_dflt_param);
   1048 	test_getsockopt(accept_sk, SCTP_DEFAULT_SEND_PARAM,
   1049 			&get_accept_assoc_dflt_param, &optlen);
   1050 
   1051 	error = 0;
   1052 
   1053 	/* Verify that the get parameters returned matches the socket-wide
   1054 	 * set param.
   1055 	 */
   1056 	if (get_tcp_sk_dflt_param.sinfo_ppid !=
   1057 			set_tcp_sk_dflt_param.sinfo_ppid)
   1058 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_DEFAULT_SEND_PARAM) "
   1059 			 "mismatch.");
   1060 
   1061 	tst_resm(TPASS, "getsockopt(SCTP_DEFAULT_SEND_PARAM) - "
   1062 		 "one-to-one style accepted socket");
   1063 
   1064 	/* TEST #7: SCTP_GET_PEER_ADDR_INFO socket option. */
   1065 	/* Try 0 associd and 0 addr */
   1066 	memset(&pinfo, 0, sizeof(pinfo));
   1067 	optlen = sizeof(pinfo);
   1068 	error = getsockopt(udp_clt_sk, SOL_SCTP, SCTP_GET_PEER_ADDR_INFO,
   1069 			   &pinfo, &optlen);
   1070 	if ((-1 != error) || (EINVAL != errno))
   1071 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_GET_PEER_ADDR_INFO) "
   1072 			 "null associd, null addr error:%d, errno:%d\n",
   1073 			error, errno);
   1074 
   1075 	tst_resm(TPASS, "getsockopt(SCTP_GET_PEER_ADDR_INFO) - "
   1076 		 "null associd and null addr");
   1077 
   1078 	/* Try valid associd, but 0 addr */
   1079 	memset(&pinfo, 0, sizeof(pinfo));
   1080 	optlen = sizeof(pinfo);
   1081 	pinfo.spinfo_assoc_id = udp_clt_associd;
   1082 	error = getsockopt(udp_clt_sk, SOL_SCTP, SCTP_GET_PEER_ADDR_INFO,
   1083 			   &pinfo, &optlen);
   1084 	if ((-1 != error) || (EINVAL != errno))
   1085 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_GET_PEER_ADDR_INFO) "
   1086 			 "valid associd, null addr error:%d, errno:%d\n",
   1087 			error, errno);
   1088 
   1089 	tst_resm(TPASS, "getsockopt(SCTP_GET_PEER_ADDR_INFO) - "
   1090 		 "valid associd and null addr");
   1091 
   1092 	/* Try valid associd, invalid addr */
   1093 	memset(&pinfo, 0, sizeof(pinfo));
   1094 	optlen = sizeof(pinfo);
   1095 	pinfo.spinfo_assoc_id = udp_clt_associd;
   1096 	memcpy(&pinfo.spinfo_address, &udp_clt_loop, sizeof(udp_clt_loop));
   1097 	error = getsockopt(udp_clt_sk, SOL_SCTP, SCTP_GET_PEER_ADDR_INFO,
   1098 			   &pinfo, &optlen);
   1099 	if ((-1 != error) || (EINVAL != errno))
   1100 		tst_brkm(TBROK, tst_exit, "getsockopt(SCTP_GET_PEER_ADDR_INFO) "
   1101 			 "valid associd, invalid addr error:%d, errno:%d\n",
   1102 			error, errno);
   1103 
   1104 	tst_resm(TPASS, "getsockopt(SCTP_GET_PEER_ADDR_INFO) - "
   1105 		 "valid associd and invalid addr");
   1106 
   1107 	/* Try valid associd, valid addr */
   1108 	memset(&pinfo, 0, sizeof(pinfo));
   1109 	optlen = sizeof(pinfo);
   1110 	pinfo.spinfo_assoc_id = udp_clt_associd;
   1111 	memcpy(&pinfo.spinfo_address, &udp_svr_loop, sizeof(udp_svr_loop));
   1112 	test_getsockopt(udp_clt_sk, SCTP_GET_PEER_ADDR_INFO, &pinfo, &optlen);
   1113 
   1114 	tst_resm(TPASS, "getsockopt(SCTP_GET_PEER_ADDR_INFO) - "
   1115 		 "valid associd and valid addr");
   1116 
   1117 	/* Try valid addr, peeled off socket */
   1118 	memset(&pinfo, 0, sizeof(pinfo));
   1119 	optlen = sizeof(pinfo);
   1120 	pinfo.spinfo_assoc_id = 0;
   1121 	memcpy(&pinfo.spinfo_address, &udp_clt_loop, sizeof(udp_clt_loop));
   1122 	test_getsockopt(peeloff_sk, SCTP_GET_PEER_ADDR_INFO, &pinfo, &optlen);
   1123 
   1124 	tst_resm(TPASS, "getsockopt(SCTP_GET_PEER_ADDR_INFO) - "
   1125 		 "valid associd and valid addr peeled off socket");
   1126 
   1127 	/* Try valid addr, TCP-style accept socket */
   1128 	memset(&pinfo, 0, sizeof(pinfo));
   1129 	optlen = sizeof(pinfo);
   1130 	pinfo.spinfo_assoc_id = 0;
   1131 	memcpy(&pinfo.spinfo_address, &tcp_clt_loop, sizeof(tcp_clt_loop));
   1132 	error = test_getsockopt(accept_sk, SCTP_GET_PEER_ADDR_INFO, &pinfo,
   1133 				&optlen);
   1134 
   1135 	tst_resm(TPASS, "getsockopt(SCTP_GET_PEER_ADDR_INFO) - "
   1136 		 "valid associd and valid addr accepted socket");
   1137 
   1138 	close(udp_svr_sk);
   1139 	close(udp_clt_sk);
   1140 	close(tcp_svr_sk);
   1141 	close(tcp_clt_sk);
   1142 	close(accept_sk);
   1143 	close(peeloff_sk);
   1144 
   1145         /* Indicate successful completion.  */
   1146         return 0;
   1147 }
   1148