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