1 /* SCTP kernel Implementation
2  * Copyright (c) 2003 Hewlett-Packard Development Company, L.P
3  * (C) Copyright IBM Corp. 2004
4  *
5  * This file has test cases to test the getsockopt () and sectsockopt () with
6  * SCTP_RTOINFO option on 1-1 style socket
7  *
8  * This program first gets the default values using getsockopt(). It also sets
9  * the value using setsockopt() and gets the set value using getsockopt().
10  * A comparison between set values and get values are performed.
11  *
12  * The SCTP implementation is free software;
13  * you can redistribute it and/or modify it under the terms of
14  * the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * The SCTP implementation is distributed in the hope that it
19  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20  *                 ************************
21  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22  * See the GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with GNU CC; see the file COPYING.  If not, write to
26  * the Free Software Foundation, 59 Temple Place - Suite 330,
27  * Boston, MA 02111-1307, USA.
28  *
29  * Please send any bug reports or fixes you make to the
30  * email address(es):
31  *    lksctp developers <lksctp-developers@lists.sourceforge.net>
32  *
33  * Or submit a bug report through the following website:
34  *    http://www.sf.net/projects/lksctp
35  *
36  * Any bugs reported given to us we will try to fix... any fixes shared will
37  * be incorporated into the next SCTP release
38  *
39  */
40 
41 #include <stdio.h>
42 #include <unistd.h>
43 #include <fcntl.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <sys/types.h>
47 #include <sys/socket.h>
48 #include <linux/socket.h>
49 #include <linux/in.h>         /* for sockaddr_in */
50 #include <linux/in6.h>         /* for sockaddr_in6 */
51 #include <sys/errno.h>
52 #include <sys/uio.h>
53 #include <netinet/sctp.h>
54 #include <sctputil.h>
55 #include "tst_kernel.h"
56 
57 char *TCID = __FILE__;
58 int TST_TOTAL = 3;
59 int TST_CNT = 0;
60 
61 int
main(void)62 main(void)
63 {
64 
65 	int sd, ret;
66 	socklen_t len;
67 	struct sctp_rtoinfo srtoinfo; /*setting the variables*/
68 	struct sctp_rtoinfo grtoinfo; /*Getting the variables*/
69 
70 	if (tst_check_driver("sctp"))
71 		tst_brkm(TCONF, tst_exit, "sctp driver not available");
72 
73 	sd = test_socket (PF_INET, SOCK_STREAM, IPPROTO_SCTP);
74 
75 	len = sizeof(struct sctp_rtoinfo);
76 
77 	/*TEST1 Getting the default values using getsockopt()*/
78 	ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len);
79 	if (ret < 0)
80 		tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO "
81 			 "ret:%d, errno:%d", ret, errno);
82 
83 	tst_resm(TPASS, "getsockopt() SCTP_RTOINFO - SUCCESS");
84 
85 	/*Assigning the values to RTO initial and max and min bounds*/
86 	srtoinfo.srto_initial=60;
87 	srtoinfo.srto_max=100;
88 	srtoinfo.srto_min=40;
89 
90 	/*TEST2 Setting the values using setsockopt()*/
91 	ret = setsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &srtoinfo,
92 		sizeof(struct sctp_rtoinfo));
93 	if (ret < 0)
94 		tst_brkm(TBROK, tst_exit, "setsockopt SCTP_RTOINFO "
95 			 "ret:%d, errno:%d", ret, errno);
96 
97 	tst_resm(TPASS, "setsockopt() SCTP_RTOINFO - SUCCESS");
98 
99 	/*Getting the values which are set using setsockopt()*/
100 	ret = getsockopt(sd, IPPROTO_SCTP, SCTP_RTOINFO, &grtoinfo, &len);
101 	if (ret < 0)
102 		tst_brkm(TBROK, tst_exit, "getsockopt SCTP_RTOINFO "
103 			 "ret:%d, errno:%d", ret, errno);
104 
105 	/* TEST3 Compare the get values with the set values. */
106 	if (srtoinfo.srto_initial != grtoinfo.srto_initial &&
107             srtoinfo.srto_max != grtoinfo.srto_max &&
108             srtoinfo.srto_min != grtoinfo.srto_min)
109 		tst_brkm(TBROK, tst_exit, "setsockopt/getsockopt SCTP_RTOINFO "
110 			 "compare failed");
111 
112 	tst_resm(TPASS, "setsockopt()/getsockopt SCTP_RTOINFO compare - "
113 		 "SUCCESS");
114 
115 	close(sd);
116 
117 	return 0;
118 }
119