xref: /aosp_15_r20/external/ltp/utils/sctp/testlib/sctputil.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /* SCTP kernel Implementation
2*49cdfc7eSAndroid Build Coastguard Worker  * (C) Copyright IBM Corp. 2001, 2003
3*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 1999-2000 Cisco, Inc.
4*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 1999-2001 Motorola, Inc.
5*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2001 Intel Corp.
6*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2001 Nokia, Inc.
7*49cdfc7eSAndroid Build Coastguard Worker  * Copyright (c) 2001 La Monte H.P. Yarroll
8*49cdfc7eSAndroid Build Coastguard Worker  *
9*49cdfc7eSAndroid Build Coastguard Worker  * The SCTP implementation is free software;
10*49cdfc7eSAndroid Build Coastguard Worker  * you can redistribute it and/or modify it under the terms of
11*49cdfc7eSAndroid Build Coastguard Worker  * the GNU General Public License as published by
12*49cdfc7eSAndroid Build Coastguard Worker  * the Free Software Foundation; either version 2, or (at your option)
13*49cdfc7eSAndroid Build Coastguard Worker  * any later version.
14*49cdfc7eSAndroid Build Coastguard Worker  *
15*49cdfc7eSAndroid Build Coastguard Worker  * The SCTP implementation is distributed in the hope that it
16*49cdfc7eSAndroid Build Coastguard Worker  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17*49cdfc7eSAndroid Build Coastguard Worker  *                 ************************
18*49cdfc7eSAndroid Build Coastguard Worker  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19*49cdfc7eSAndroid Build Coastguard Worker  * See the GNU General Public License for more details.
20*49cdfc7eSAndroid Build Coastguard Worker  *
21*49cdfc7eSAndroid Build Coastguard Worker  * You should have received a copy of the GNU General Public License
22*49cdfc7eSAndroid Build Coastguard Worker  * along with GNU CC; see the file COPYING.  If not, write to
23*49cdfc7eSAndroid Build Coastguard Worker  * the Free Software Foundation, 59 Temple Place - Suite 330,
24*49cdfc7eSAndroid Build Coastguard Worker  * Boston, MA 02111-1307, USA.
25*49cdfc7eSAndroid Build Coastguard Worker  *
26*49cdfc7eSAndroid Build Coastguard Worker  * Please send any bug reports or fixes you make to the
27*49cdfc7eSAndroid Build Coastguard Worker  * email address(es):
28*49cdfc7eSAndroid Build Coastguard Worker  *    lksctp developers <[email protected]>
29*49cdfc7eSAndroid Build Coastguard Worker  *
30*49cdfc7eSAndroid Build Coastguard Worker  * Or submit a bug report through the following website:
31*49cdfc7eSAndroid Build Coastguard Worker  *    http://www.sf.net/projects/lksctp
32*49cdfc7eSAndroid Build Coastguard Worker  *
33*49cdfc7eSAndroid Build Coastguard Worker  * Any bugs reported to us we will try to fix... any fixes shared will
34*49cdfc7eSAndroid Build Coastguard Worker  * be incorporated into the next SCTP release.
35*49cdfc7eSAndroid Build Coastguard Worker  *
36*49cdfc7eSAndroid Build Coastguard Worker  * Written or modified by:
37*49cdfc7eSAndroid Build Coastguard Worker  *    La Monte H.P. Yarroll <[email protected]>
38*49cdfc7eSAndroid Build Coastguard Worker  *    Karl Knutson <[email protected]>
39*49cdfc7eSAndroid Build Coastguard Worker  *    Randall Stewart <[email protected]>
40*49cdfc7eSAndroid Build Coastguard Worker  *    Ken Morneau <[email protected]>
41*49cdfc7eSAndroid Build Coastguard Worker  *    Qiaobing Xie <[email protected]>
42*49cdfc7eSAndroid Build Coastguard Worker  *    Daisy Chang <[email protected]>
43*49cdfc7eSAndroid Build Coastguard Worker  *    Jon Grimm <[email protected]>
44*49cdfc7eSAndroid Build Coastguard Worker  *    Sridhar Samudrala <[email protected]>
45*49cdfc7eSAndroid Build Coastguard Worker  *    Hui Huang <[email protected]>
46*49cdfc7eSAndroid Build Coastguard Worker  */
47*49cdfc7eSAndroid Build Coastguard Worker 
48*49cdfc7eSAndroid Build Coastguard Worker #ifndef __sctputil_h__
49*49cdfc7eSAndroid Build Coastguard Worker #define __sctputil_h__
50*49cdfc7eSAndroid Build Coastguard Worker 
51*49cdfc7eSAndroid Build Coastguard Worker #ifdef LTP
52*49cdfc7eSAndroid Build Coastguard Worker #include <test.h>
53*49cdfc7eSAndroid Build Coastguard Worker #include <usctest.h>
54*49cdfc7eSAndroid Build Coastguard Worker #endif
55*49cdfc7eSAndroid Build Coastguard Worker 
56*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
57*49cdfc7eSAndroid Build Coastguard Worker 
58*49cdfc7eSAndroid Build Coastguard Worker typedef union {
59*49cdfc7eSAndroid Build Coastguard Worker 	struct sockaddr_in v4;
60*49cdfc7eSAndroid Build Coastguard Worker 	struct sockaddr_in6 v6;
61*49cdfc7eSAndroid Build Coastguard Worker 	struct sockaddr sa;
62*49cdfc7eSAndroid Build Coastguard Worker } sockaddr_storage_t;
63*49cdfc7eSAndroid Build Coastguard Worker 
64*49cdfc7eSAndroid Build Coastguard Worker 
65*49cdfc7eSAndroid Build Coastguard Worker #define REALLY_BIG 65536
66*49cdfc7eSAndroid Build Coastguard Worker 
67*49cdfc7eSAndroid Build Coastguard Worker /* Literal defines.  */
68*49cdfc7eSAndroid Build Coastguard Worker #ifdef PROT_SOCK
69*49cdfc7eSAndroid Build Coastguard Worker #define SCTP_TESTPORT_1 PROT_SOCK
70*49cdfc7eSAndroid Build Coastguard Worker #else
71*49cdfc7eSAndroid Build Coastguard Worker #define SCTP_TESTPORT_1 1024
72*49cdfc7eSAndroid Build Coastguard Worker #endif
73*49cdfc7eSAndroid Build Coastguard Worker #define SCTP_TESTPORT_2 (SCTP_TESTPORT_1+1)
74*49cdfc7eSAndroid Build Coastguard Worker 
75*49cdfc7eSAndroid Build Coastguard Worker #define SCTP_IP_BCAST  	htonl(0xffffffff)
76*49cdfc7eSAndroid Build Coastguard Worker #define SCTP_IP_LOOPBACK  htonl(0x7f000001)
77*49cdfc7eSAndroid Build Coastguard Worker 
78*49cdfc7eSAndroid Build Coastguard Worker /* These are stolen from <netinet/in.h>.  */
79*49cdfc7eSAndroid Build Coastguard Worker #define SCTP_IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
80*49cdfc7eSAndroid Build Coastguard Worker #define SCTP_IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
81*49cdfc7eSAndroid Build Coastguard Worker 
82*49cdfc7eSAndroid Build Coastguard Worker /* Display an IPv4 address in readable format.  */
83*49cdfc7eSAndroid Build Coastguard Worker #define NIPQUAD(addr) \
84*49cdfc7eSAndroid Build Coastguard Worker         ((unsigned char *)&addr)[0], \
85*49cdfc7eSAndroid Build Coastguard Worker         ((unsigned char *)&addr)[1], \
86*49cdfc7eSAndroid Build Coastguard Worker         ((unsigned char *)&addr)[2], \
87*49cdfc7eSAndroid Build Coastguard Worker         ((unsigned char *)&addr)[3]
88*49cdfc7eSAndroid Build Coastguard Worker 
89*49cdfc7eSAndroid Build Coastguard Worker /* Display an IPv6 address in readable format.  */
90*49cdfc7eSAndroid Build Coastguard Worker #define NIP6(addr) \
91*49cdfc7eSAndroid Build Coastguard Worker         ntohs((addr).s6_addr16[0]), \
92*49cdfc7eSAndroid Build Coastguard Worker         ntohs((addr).s6_addr16[1]), \
93*49cdfc7eSAndroid Build Coastguard Worker         ntohs((addr).s6_addr16[2]), \
94*49cdfc7eSAndroid Build Coastguard Worker         ntohs((addr).s6_addr16[3]), \
95*49cdfc7eSAndroid Build Coastguard Worker         ntohs((addr).s6_addr16[4]), \
96*49cdfc7eSAndroid Build Coastguard Worker         ntohs((addr).s6_addr16[5]), \
97*49cdfc7eSAndroid Build Coastguard Worker         ntohs((addr).s6_addr16[6]), \
98*49cdfc7eSAndroid Build Coastguard Worker         ntohs((addr).s6_addr16[7])
99*49cdfc7eSAndroid Build Coastguard Worker 
100*49cdfc7eSAndroid Build Coastguard Worker #define DUMP_CORE { 					 \
101*49cdfc7eSAndroid Build Coastguard Worker 	char *diediedie = 0;				 \
102*49cdfc7eSAndroid Build Coastguard Worker 	printf("DUMP_CORE %s: %d\n", __FILE__, __LINE__);\
103*49cdfc7eSAndroid Build Coastguard Worker 	*diediedie = 0;					 \
104*49cdfc7eSAndroid Build Coastguard Worker }
105*49cdfc7eSAndroid Build Coastguard Worker 
106*49cdfc7eSAndroid Build Coastguard Worker #ifndef LTP
107*49cdfc7eSAndroid Build Coastguard Worker enum {
108*49cdfc7eSAndroid Build Coastguard Worker 	TPASS,
109*49cdfc7eSAndroid Build Coastguard Worker 	TINFO,
110*49cdfc7eSAndroid Build Coastguard Worker };
111*49cdfc7eSAndroid Build Coastguard Worker 
112*49cdfc7eSAndroid Build Coastguard Worker extern char *TCID;
113*49cdfc7eSAndroid Build Coastguard Worker extern int TST_TOTAL;
114*49cdfc7eSAndroid Build Coastguard Worker extern int TST_CNT;
115*49cdfc7eSAndroid Build Coastguard Worker 
116*49cdfc7eSAndroid Build Coastguard Worker #define tst_brkm(a1, a2, whatever...) \
117*49cdfc7eSAndroid Build Coastguard Worker 	{ \
118*49cdfc7eSAndroid Build Coastguard Worker 		printf("%s %2d BROK : ", TCID, ++TST_CNT); \
119*49cdfc7eSAndroid Build Coastguard Worker 		printf(whatever); \
120*49cdfc7eSAndroid Build Coastguard Worker 		printf("\n"); \
121*49cdfc7eSAndroid Build Coastguard Worker 		DUMP_CORE \
122*49cdfc7eSAndroid Build Coastguard Worker 	}
123*49cdfc7eSAndroid Build Coastguard Worker #define tst_resm(a1, whatever...) \
124*49cdfc7eSAndroid Build Coastguard Worker 	{ \
125*49cdfc7eSAndroid Build Coastguard Worker 		printf("%s %2d %s : ", TCID, \
126*49cdfc7eSAndroid Build Coastguard Worker 			 (a1 == TPASS)?++TST_CNT:0, \
127*49cdfc7eSAndroid Build Coastguard Worker 			 (a1 == TPASS)?"PASS":"INFO"); \
128*49cdfc7eSAndroid Build Coastguard Worker 		printf(whatever); \
129*49cdfc7eSAndroid Build Coastguard Worker 		printf("\n"); \
130*49cdfc7eSAndroid Build Coastguard Worker 	}
131*49cdfc7eSAndroid Build Coastguard Worker #endif
132*49cdfc7eSAndroid Build Coastguard Worker 
test_socket(int domain,int type,int protocol)133*49cdfc7eSAndroid Build Coastguard Worker static inline int test_socket(int domain, int type, int protocol)
134*49cdfc7eSAndroid Build Coastguard Worker {
135*49cdfc7eSAndroid Build Coastguard Worker 	int sk = socket(domain, type, protocol);
136*49cdfc7eSAndroid Build Coastguard Worker 
137*49cdfc7eSAndroid Build Coastguard Worker 	if (sk == -1) {
138*49cdfc7eSAndroid Build Coastguard Worker 		if (errno == EAFNOSUPPORT)
139*49cdfc7eSAndroid Build Coastguard Worker 			tst_brkm(TCONF | TERRNO, tst_exit, "socket(%i, %i, %i) not supported", domain,
140*49cdfc7eSAndroid Build Coastguard Worker 					 type, protocol);
141*49cdfc7eSAndroid Build Coastguard Worker 
142*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "socket()");
143*49cdfc7eSAndroid Build Coastguard Worker 	}
144*49cdfc7eSAndroid Build Coastguard Worker 
145*49cdfc7eSAndroid Build Coastguard Worker 	return sk;
146*49cdfc7eSAndroid Build Coastguard Worker }
147*49cdfc7eSAndroid Build Coastguard Worker 
test_bind(int sk,struct sockaddr * addr,socklen_t addrlen)148*49cdfc7eSAndroid Build Coastguard Worker static inline int test_bind(int sk, struct sockaddr *addr, socklen_t addrlen)
149*49cdfc7eSAndroid Build Coastguard Worker {
150*49cdfc7eSAndroid Build Coastguard Worker 	int error = bind(sk, addr, addrlen);
151*49cdfc7eSAndroid Build Coastguard Worker 
152*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
153*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "bind()");
154*49cdfc7eSAndroid Build Coastguard Worker 
155*49cdfc7eSAndroid Build Coastguard Worker 	return error;
156*49cdfc7eSAndroid Build Coastguard Worker }
157*49cdfc7eSAndroid Build Coastguard Worker 
test_bindx_add(int sk,struct sockaddr * addr,int count)158*49cdfc7eSAndroid Build Coastguard Worker static inline int test_bindx_add(int sk, struct sockaddr *addr, int count)
159*49cdfc7eSAndroid Build Coastguard Worker {
160*49cdfc7eSAndroid Build Coastguard Worker 	int error = sctp_bindx(sk, addr, count, SCTP_BINDX_ADD_ADDR);
161*49cdfc7eSAndroid Build Coastguard Worker 
162*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
163*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "sctp_bindx()");
164*49cdfc7eSAndroid Build Coastguard Worker 
165*49cdfc7eSAndroid Build Coastguard Worker 	return error;
166*49cdfc7eSAndroid Build Coastguard Worker }
167*49cdfc7eSAndroid Build Coastguard Worker 
test_listen(int sk,int backlog)168*49cdfc7eSAndroid Build Coastguard Worker static inline int test_listen(int sk, int backlog)
169*49cdfc7eSAndroid Build Coastguard Worker {
170*49cdfc7eSAndroid Build Coastguard Worker 	int error = listen(sk, backlog);
171*49cdfc7eSAndroid Build Coastguard Worker 
172*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
173*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "listen()");
174*49cdfc7eSAndroid Build Coastguard Worker 
175*49cdfc7eSAndroid Build Coastguard Worker 	return error;
176*49cdfc7eSAndroid Build Coastguard Worker }
177*49cdfc7eSAndroid Build Coastguard Worker 
test_connect(int sk,struct sockaddr * addr,socklen_t addrlen)178*49cdfc7eSAndroid Build Coastguard Worker static inline int test_connect(int sk, struct sockaddr *addr, socklen_t addrlen)
179*49cdfc7eSAndroid Build Coastguard Worker {
180*49cdfc7eSAndroid Build Coastguard Worker 	int error = connect(sk, addr, addrlen);
181*49cdfc7eSAndroid Build Coastguard Worker 
182*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
183*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "connect()");
184*49cdfc7eSAndroid Build Coastguard Worker 
185*49cdfc7eSAndroid Build Coastguard Worker 	return error;
186*49cdfc7eSAndroid Build Coastguard Worker }
187*49cdfc7eSAndroid Build Coastguard Worker 
test_connectx(int sk,struct sockaddr * addr,int count)188*49cdfc7eSAndroid Build Coastguard Worker static inline int test_connectx(int sk, struct sockaddr *addr, int count)
189*49cdfc7eSAndroid Build Coastguard Worker {
190*49cdfc7eSAndroid Build Coastguard Worker 	int error = sctp_connectx(sk, addr, count, NULL);
191*49cdfc7eSAndroid Build Coastguard Worker 
192*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
193*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "connectx()");
194*49cdfc7eSAndroid Build Coastguard Worker 
195*49cdfc7eSAndroid Build Coastguard Worker 	return error;
196*49cdfc7eSAndroid Build Coastguard Worker }
197*49cdfc7eSAndroid Build Coastguard Worker 
test_accept(int sk,struct sockaddr * addr,socklen_t * addrlen)198*49cdfc7eSAndroid Build Coastguard Worker static inline int test_accept(int sk, struct sockaddr *addr, socklen_t *addrlen)
199*49cdfc7eSAndroid Build Coastguard Worker {
200*49cdfc7eSAndroid Build Coastguard Worker 	int error = accept(sk, addr, addrlen);
201*49cdfc7eSAndroid Build Coastguard Worker 
202*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
203*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "accept()");
204*49cdfc7eSAndroid Build Coastguard Worker 
205*49cdfc7eSAndroid Build Coastguard Worker 	return error;
206*49cdfc7eSAndroid Build Coastguard Worker }
207*49cdfc7eSAndroid Build Coastguard Worker 
test_send(int sk,const void * msg,size_t len,int flags)208*49cdfc7eSAndroid Build Coastguard Worker static inline int test_send(int sk, const void *msg, size_t len, int flags)
209*49cdfc7eSAndroid Build Coastguard Worker {
210*49cdfc7eSAndroid Build Coastguard Worker 	int error = send(sk, msg, len, flags);
211*49cdfc7eSAndroid Build Coastguard Worker 
212*49cdfc7eSAndroid Build Coastguard Worker 	if ((long)len != error)
213*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "send(): error: %d", error);
214*49cdfc7eSAndroid Build Coastguard Worker 
215*49cdfc7eSAndroid Build Coastguard Worker 	return error;
216*49cdfc7eSAndroid Build Coastguard Worker }
217*49cdfc7eSAndroid Build Coastguard Worker 
test_sendto(int sk,const void * msg,size_t len,int flags,const struct sockaddr * to,socklen_t tolen)218*49cdfc7eSAndroid Build Coastguard Worker static inline int test_sendto(int sk, const void *msg, size_t len, int flags,
219*49cdfc7eSAndroid Build Coastguard Worker 			      const struct sockaddr *to, socklen_t tolen)
220*49cdfc7eSAndroid Build Coastguard Worker {
221*49cdfc7eSAndroid Build Coastguard Worker 	int error = sendto(sk, msg, len, flags, to, tolen);
222*49cdfc7eSAndroid Build Coastguard Worker 
223*49cdfc7eSAndroid Build Coastguard Worker 	if ((long)len != error)
224*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "sendto(): error: %d", error);
225*49cdfc7eSAndroid Build Coastguard Worker 
226*49cdfc7eSAndroid Build Coastguard Worker 	return error;
227*49cdfc7eSAndroid Build Coastguard Worker }
228*49cdfc7eSAndroid Build Coastguard Worker 
test_sendmsg(int sk,const struct msghdr * msg,int flags,int msglen)229*49cdfc7eSAndroid Build Coastguard Worker static inline int test_sendmsg(int sk, const struct msghdr *msg, int flags,
230*49cdfc7eSAndroid Build Coastguard Worker 			       int msglen)
231*49cdfc7eSAndroid Build Coastguard Worker {
232*49cdfc7eSAndroid Build Coastguard Worker 	int error = sendmsg(sk, msg, flags);
233*49cdfc7eSAndroid Build Coastguard Worker 
234*49cdfc7eSAndroid Build Coastguard Worker 	if (msglen != error)
235*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "sendmsg(): error: %d", error);
236*49cdfc7eSAndroid Build Coastguard Worker 
237*49cdfc7eSAndroid Build Coastguard Worker 	return error;
238*49cdfc7eSAndroid Build Coastguard Worker }
239*49cdfc7eSAndroid Build Coastguard Worker 
test_recv(int sk,void * buf,size_t len,int flags)240*49cdfc7eSAndroid Build Coastguard Worker static inline int test_recv(int sk, void *buf, size_t len, int flags)
241*49cdfc7eSAndroid Build Coastguard Worker {
242*49cdfc7eSAndroid Build Coastguard Worker 	int error = recv(sk, buf, len, flags);
243*49cdfc7eSAndroid Build Coastguard Worker 
244*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
245*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "recv()");
246*49cdfc7eSAndroid Build Coastguard Worker 
247*49cdfc7eSAndroid Build Coastguard Worker 	return error;
248*49cdfc7eSAndroid Build Coastguard Worker }
249*49cdfc7eSAndroid Build Coastguard Worker 
test_recvmsg(int sk,struct msghdr * msg,int flags)250*49cdfc7eSAndroid Build Coastguard Worker static inline int test_recvmsg(int sk, struct msghdr *msg, int flags)
251*49cdfc7eSAndroid Build Coastguard Worker {
252*49cdfc7eSAndroid Build Coastguard Worker 	int error = recvmsg(sk, msg, flags);
253*49cdfc7eSAndroid Build Coastguard Worker 
254*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
255*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "recvmsg()");
256*49cdfc7eSAndroid Build Coastguard Worker 
257*49cdfc7eSAndroid Build Coastguard Worker 	return error;
258*49cdfc7eSAndroid Build Coastguard Worker }
259*49cdfc7eSAndroid Build Coastguard Worker 
test_shutdown(int sk,int how)260*49cdfc7eSAndroid Build Coastguard Worker static inline int test_shutdown(int sk, int how)
261*49cdfc7eSAndroid Build Coastguard Worker {
262*49cdfc7eSAndroid Build Coastguard Worker 	int error = shutdown(sk, how);
263*49cdfc7eSAndroid Build Coastguard Worker 
264*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
265*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "shutdown()");
266*49cdfc7eSAndroid Build Coastguard Worker 
267*49cdfc7eSAndroid Build Coastguard Worker 	return error;
268*49cdfc7eSAndroid Build Coastguard Worker }
269*49cdfc7eSAndroid Build Coastguard Worker 
test_getsockopt(int sk,int optname,void * optval,socklen_t * optlen)270*49cdfc7eSAndroid Build Coastguard Worker static inline int test_getsockopt(int sk, int optname, void *optval,
271*49cdfc7eSAndroid Build Coastguard Worker 				  socklen_t *optlen)
272*49cdfc7eSAndroid Build Coastguard Worker {
273*49cdfc7eSAndroid Build Coastguard Worker 	int error = getsockopt(sk, SOL_SCTP, optname, optval, optlen);
274*49cdfc7eSAndroid Build Coastguard Worker 
275*49cdfc7eSAndroid Build Coastguard Worker 	if (error)
276*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK, tst_exit, "getsockopt(%d): %s", optname,
277*49cdfc7eSAndroid Build Coastguard Worker 			 strerror(errno));
278*49cdfc7eSAndroid Build Coastguard Worker 	return error;
279*49cdfc7eSAndroid Build Coastguard Worker }
280*49cdfc7eSAndroid Build Coastguard Worker 
test_setsockopt(int sk,int optname,const void * optval,socklen_t optlen)281*49cdfc7eSAndroid Build Coastguard Worker static inline int test_setsockopt(int sk, int optname, const void *optval,
282*49cdfc7eSAndroid Build Coastguard Worker 				  socklen_t optlen)
283*49cdfc7eSAndroid Build Coastguard Worker {
284*49cdfc7eSAndroid Build Coastguard Worker 	int error = setsockopt(sk, SOL_SCTP, optname, optval, optlen);
285*49cdfc7eSAndroid Build Coastguard Worker 
286*49cdfc7eSAndroid Build Coastguard Worker 	if (error)
287*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK, tst_exit, "setsockopt(%d): %s", optname,
288*49cdfc7eSAndroid Build Coastguard Worker 			 strerror(errno));
289*49cdfc7eSAndroid Build Coastguard Worker 
290*49cdfc7eSAndroid Build Coastguard Worker 	return error;
291*49cdfc7eSAndroid Build Coastguard Worker }
292*49cdfc7eSAndroid Build Coastguard Worker 
test_sctp_peeloff(int sk,sctp_assoc_t assoc_id)293*49cdfc7eSAndroid Build Coastguard Worker static inline int test_sctp_peeloff(int sk, sctp_assoc_t assoc_id)
294*49cdfc7eSAndroid Build Coastguard Worker {
295*49cdfc7eSAndroid Build Coastguard Worker 	int error = sctp_peeloff(sk, assoc_id);
296*49cdfc7eSAndroid Build Coastguard Worker 
297*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
298*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "sctp_peeloff()");
299*49cdfc7eSAndroid Build Coastguard Worker 
300*49cdfc7eSAndroid Build Coastguard Worker 	return error;
301*49cdfc7eSAndroid Build Coastguard Worker }
302*49cdfc7eSAndroid Build Coastguard Worker 
test_sctp_sendmsg(int s,const void * msg,size_t len,struct sockaddr * to,socklen_t tolen,uint32_t ppid,uint32_t flags,uint16_t stream_no,uint32_t timetolive,uint32_t context)303*49cdfc7eSAndroid Build Coastguard Worker static inline int test_sctp_sendmsg(int s, const void *msg, size_t len,
304*49cdfc7eSAndroid Build Coastguard Worker 				    struct sockaddr *to, socklen_t tolen,
305*49cdfc7eSAndroid Build Coastguard Worker 				    uint32_t ppid, uint32_t flags,
306*49cdfc7eSAndroid Build Coastguard Worker 				    uint16_t stream_no, uint32_t timetolive,
307*49cdfc7eSAndroid Build Coastguard Worker 				    uint32_t context)
308*49cdfc7eSAndroid Build Coastguard Worker {
309*49cdfc7eSAndroid Build Coastguard Worker 	int error = sctp_sendmsg(s, msg, len, to, tolen, ppid, flags, stream_no,
310*49cdfc7eSAndroid Build Coastguard Worker 				 timetolive, context);
311*49cdfc7eSAndroid Build Coastguard Worker 
312*49cdfc7eSAndroid Build Coastguard Worker 	if (error != (long)len)
313*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK, tst_exit, "sctp_sendmsg: error:%d errno:%d",
314*49cdfc7eSAndroid Build Coastguard Worker 			 error, errno);
315*49cdfc7eSAndroid Build Coastguard Worker 
316*49cdfc7eSAndroid Build Coastguard Worker 	return error;
317*49cdfc7eSAndroid Build Coastguard Worker }
318*49cdfc7eSAndroid Build Coastguard Worker 
test_sctp_send(int s,const void * msg,size_t len,const struct sctp_sndrcvinfo * sinfo,int flags)319*49cdfc7eSAndroid Build Coastguard Worker static inline int test_sctp_send(int s, const void *msg, size_t len,
320*49cdfc7eSAndroid Build Coastguard Worker 				 const struct sctp_sndrcvinfo *sinfo,
321*49cdfc7eSAndroid Build Coastguard Worker 				 int flags)
322*49cdfc7eSAndroid Build Coastguard Worker {
323*49cdfc7eSAndroid Build Coastguard Worker 	int error = sctp_send(s, msg, len, sinfo, flags);
324*49cdfc7eSAndroid Build Coastguard Worker 
325*49cdfc7eSAndroid Build Coastguard Worker 	if (error != (long)len)
326*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK, tst_exit, "sctp_send: error:%d errno:%d",
327*49cdfc7eSAndroid Build Coastguard Worker 			 error, errno);
328*49cdfc7eSAndroid Build Coastguard Worker 
329*49cdfc7eSAndroid Build Coastguard Worker 	return error;
330*49cdfc7eSAndroid Build Coastguard Worker }
331*49cdfc7eSAndroid Build Coastguard Worker 
test_sctp_recvmsg(int sk,void * msg,size_t len,struct sockaddr * from,socklen_t * fromlen,struct sctp_sndrcvinfo * sinfo,int * msg_flags)332*49cdfc7eSAndroid Build Coastguard Worker static inline int test_sctp_recvmsg(int sk, void *msg, size_t len,
333*49cdfc7eSAndroid Build Coastguard Worker 				    struct sockaddr *from, socklen_t *fromlen,
334*49cdfc7eSAndroid Build Coastguard Worker 				    struct sctp_sndrcvinfo *sinfo,
335*49cdfc7eSAndroid Build Coastguard Worker 				    int *msg_flags)
336*49cdfc7eSAndroid Build Coastguard Worker {
337*49cdfc7eSAndroid Build Coastguard Worker 	int error = sctp_recvmsg(sk, msg, len, from, fromlen, sinfo, msg_flags);
338*49cdfc7eSAndroid Build Coastguard Worker 
339*49cdfc7eSAndroid Build Coastguard Worker 	if (error == -1)
340*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, tst_exit, "sctp_recvmsg()");
341*49cdfc7eSAndroid Build Coastguard Worker 
342*49cdfc7eSAndroid Build Coastguard Worker 	return error;
343*49cdfc7eSAndroid Build Coastguard Worker }
344*49cdfc7eSAndroid Build Coastguard Worker 
test_malloc(size_t size)345*49cdfc7eSAndroid Build Coastguard Worker static inline void *test_malloc(size_t size)
346*49cdfc7eSAndroid Build Coastguard Worker {
347*49cdfc7eSAndroid Build Coastguard Worker 	void *buf = malloc(size);
348*49cdfc7eSAndroid Build Coastguard Worker 
349*49cdfc7eSAndroid Build Coastguard Worker 	if (NULL == buf)
350*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK, tst_exit, "malloc failed");
351*49cdfc7eSAndroid Build Coastguard Worker 
352*49cdfc7eSAndroid Build Coastguard Worker 	return buf;
353*49cdfc7eSAndroid Build Coastguard Worker }
354*49cdfc7eSAndroid Build Coastguard Worker 
355*49cdfc7eSAndroid Build Coastguard Worker void test_check_msg_notification(struct msghdr *, int, int, uint16_t, uint32_t);
356*49cdfc7eSAndroid Build Coastguard Worker void test_check_buf_notification(void *, int, int, int, uint16_t, uint32_t);
357*49cdfc7eSAndroid Build Coastguard Worker void test_check_msg_data(struct msghdr *, int, int, int, uint16_t, uint32_t);
358*49cdfc7eSAndroid Build Coastguard Worker void test_check_buf_data(void *, int, int, struct sctp_sndrcvinfo *, int, int,
359*49cdfc7eSAndroid Build Coastguard Worker 			 uint16_t, uint32_t);
360*49cdfc7eSAndroid Build Coastguard Worker void *test_build_msg(int);
361*49cdfc7eSAndroid Build Coastguard Worker void test_enable_assoc_change(int);
362*49cdfc7eSAndroid Build Coastguard Worker void test_print_message(int sk, struct msghdr *msg, size_t msg_len);
363*49cdfc7eSAndroid Build Coastguard Worker int test_peer_addr(int sk, sctp_assoc_t asoc, sockaddr_storage_t *peers, int count);
364*49cdfc7eSAndroid Build Coastguard Worker 
365*49cdfc7eSAndroid Build Coastguard Worker #endif /* __sctputil_h__ */
366