asapi_03.c revision 43088e16aa60d69e3ec5a69cdd8bdd45b8891127
1/*
2 *
3 *   Copyright (c) International Business Machines  Corp., 2001
4 *
5 *   This program is free software;  you can redistribute it and/or modify
6 *   it under the terms of the GNU General Public License as published by
7 *   the Free Software Foundation; either version 2 of the License, or
8 *   (at your option) any later version.
9 *
10 *   This program is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13 *   the GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with this program;  if not, write to the Free Software
17 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * Test Name: asapi_03
22 *
23 * Test Description:
24 *  These tests are for the "Advanced Sockets API" (RFC 3542)
25 *  Verify that in6 and sockaddr fields are present.
26 *
27 * Usage:  <for command-line>
28 *  asapi_03
29 *
30 * HISTORY
31 *	03/2005 written by David L Stevens
32 *
33 * RESTRICTIONS:
34 *  None.
35 *
36 */
37
38#include <stdio.h>
39#include <unistd.h>
40#include <errno.h>
41
42#include <sys/wait.h>
43
44#include <netinet/ip6.h>
45
46#include "test.h"
47#include "usctest.h"
48#include "runcc.h"
49
50char *TCID="asapi_03";		/* Test program identifier.    */
51
52void setup(void), cleanup(void);
53
54enum ttype { EXISTS, ALIAS, VALUE };
55
56struct ftent {
57	char	*ft_tname;		/* test name */
58	int	ft_type;		/* test type */
59	char	*ft_incl;		/* include file list */
60	char	*ft_struct;		/* structure name */
61	char	*ft_field;		/* field name */
62	char	*ft_offset;		/* field offset */
63	union {
64		char	*fu_value;	/* field size or value */
65		char	*fu_dname;	/* #define name */
66	} ftun;
67#define ft_value	ftun.fu_value
68#define ft_dname	ftun.fu_dname
69} ftab[] = {
70/* section 2.2.3, MLDv1 */
71	{ "MLD_LISTENER_QUERY", VALUE, ICMP6_H, "MLD_LISTENER_QUERY",
72		NULL, NULL, {"130"} },
73	{ "MLD_LISTENER_REPORT", VALUE, ICMP6_H, "MLD_LISTENER_REPORT",
74		NULL, NULL, {"131"} },
75	{ "MLD_LISTENER_REDUCTION", VALUE, ICMP6_H, "MLD_LISTENER_REDUCTION",
76		NULL, NULL, {"132"} },
77	{ "mld_hdr mld_icmp6_hdr", EXISTS, ICMP6_H, "mld_hdr",
78		"mld_icmp6_hdr", "0", {"sizeof(struct icmp6_hdr)"} },
79	{ "mld_hdr mld_addr", EXISTS, ICMP6_H, "mld_hdr", "mld_addr",
80		"sizeof(struct icmp6_hdr)",
81		{"sizeof(struct in6_addr)"} },
82	{ "mld_hdr mld_type define", ALIAS, ICMP6_H, "mld_hdr",
83		"mld_icmp6_hdr.icmp6_type", NULL, {"mld_type"} },
84	{ "mld_hdr mld_code define", ALIAS, ICMP6_H, "mld_hdr",
85		"mld_icmp6_hdr.icmp6_code", NULL, {"mld_code"} },
86	{ "mld_hdr mld_cksum define", ALIAS, ICMP6_H, "mld_hdr",
87		"mld_icmp6_hdr.icmp6_cksum", NULL, {"mld_cksum"} },
88	{ "mld_hdr mld_maxdelay define", ALIAS, ICMP6_H, "mld_hdr",
89		"mld_icmp6_hdr.icmp6_data16[0]", NULL, {"mld_maxdelay"} },
90	{ "mld_hdr mld_reserved define", ALIAS, ICMP6_H, "mld_hdr",
91		"mld_icmp6_hdr.icmp6_data16[1]", NULL, {"mld_reserved"} },
92/* section 2.2.4, Router renumbering */
93	{ "ICMP6_ROUTER_RENUMBERING", VALUE, ICMP6_H,"ICMP6_ROUTER_RENUMBERING",
94		NULL, NULL, {"138"} },
95	{ "icmp6_router_renum rr_hdr", EXISTS, ICMP6_H, "icmp6_router_renum",
96		"rr_hdr", "0", {"sizeof(struct icmp6_hdr)"} },
97	{ "icmp6_router_renum rr_segnum", EXISTS, ICMP6_H, "icmp6_router_renum",
98		"rr_segnum", "sizeof(struct icmp6_hdr)", {"1"} },
99	{ "icmp6_router_renum rr_flags", EXISTS, ICMP6_H, "icmp6_router_renum",
100		"rr_flags", "sizeof(struct icmp6_hdr)+1", {"1"} },
101	{ "icmp6_router_renum rr_maxdelay", EXISTS, ICMP6_H,
102		"icmp6_router_renum", "rr_maxdelay",
103		"sizeof(struct icmp6_hdr)+2",  {"2"} },
104	{ "icmp6_router_renum rr_reserved", EXISTS, ICMP6_H,
105		"icmp6_router_renum", "rr_reserved",
106		"sizeof(struct icmp6_hdr)+4", {"4"} },
107	{ "icmp6_router_renum rr_type define", ALIAS, ICMP6_H,
108		"icmp6_router_renum", "rr_hdr.icmp6_type",
109		NULL, {"rr_type"} },
110	{ "icmp6_router_renum rr_code define", ALIAS, ICMP6_H,
111		"icmp6_router_renum", "rr_hdr.icmp6_code",
112		NULL, {"rr_code"} },
113	{ "icmp6_router_renum rr_cksum define", ALIAS, ICMP6_H,
114		"icmp6_router_renum", "rr_hdr.icmp6_cksum",
115		NULL, {"rr_cksum"} },
116	{ "icmp6_router_renum rr_seqnum define", ALIAS, ICMP6_H,
117		"icmp6_router_renum", "rr_hdr.icmp6_data32[0]",
118		NULL, {"rr_seqnum"} },
119	{ "ICMP6_RR_FLAGS_TEST", VALUE, ICMP6_H, "ICMP6_RR_FLAGS_TEST",
120		NULL, NULL, {"0x80"} },
121	{ "ICMP6_RR_FLAGS_REQRESULT", VALUE, ICMP6_H,
122		"ICMP6_RR_FLAGS_REQRESULT", NULL, NULL, {"0x40"} },
123	{ "ICMP6_RR_FLAGS_FORCEAPPLY", VALUE, ICMP6_H,
124		"ICMP6_RR_FLAGS_FORCEAPPLY", NULL, NULL, {"0x20"} },
125	{ "ICMP6_RR_FLAGS_SPECSITE", VALUE, ICMP6_H,
126		"ICMP6_RR_FLAGS_SPECSITE", NULL, NULL, {"0x10"} },
127	{ "ICMP6_RR_FLAGS_PREVDONE", VALUE, ICMP6_H,
128		"ICMP6_RR_FLAGS_PREVDONE", NULL, NULL, {"0x08"} },
129
130	{ "rr_pco_match rpm_code", EXISTS, ICMP6_H, "rr_pco_match",
131		"rpm_code", "0", {"1"} },
132	{ "rr_pco_match rpm_len", EXISTS, ICMP6_H, "rr_pco_match",
133		"rpm_len", "1", {"1"} },
134	{ "rr_pco_match rpm_ordinal", EXISTS, ICMP6_H, "rr_pco_match",
135		"rpm_ordinal", "2", {"1"} },
136	{ "rr_pco_match rpm_matchlen", EXISTS, ICMP6_H, "rr_pco_match",
137		"rpm_matchlen", "3", {"1"} },
138	{ "rr_pco_match rpm_minlen", EXISTS, ICMP6_H, "rr_pco_match",
139		"rpm_minlen", "4", {"1"} },
140	{ "rr_pco_match rpm_maxlen", EXISTS, ICMP6_H, "rr_pco_match",
141		"rpm_maxlen", "5", {"1"} },
142	{ "rr_pco_match rpm_reserved", EXISTS, ICMP6_H, "rr_pco_match",
143		"rpm_reserved", "6", {"2"} },
144	{ "rr_pco_match rpm_prefix", EXISTS, ICMP6_H, "rr_pco_match",
145		"rpm_prefix", "8", {"sizeof(struct in6_addr)"} },
146
147	{ "RPM_PCO_ADD", VALUE, ICMP6_H, "RPM_PCO_ADD", NULL, NULL, {"1"} },
148	{ "RPM_PCO_CHANGE", VALUE, ICMP6_H, "RPM_PCO_CHANGE", NULL, NULL,
149		{"2"} },
150	{ "RPM_PCO_SETGLOBAL", VALUE, ICMP6_H, "RPM_PCO_SETGLOBAL", NULL, NULL,
151		{"3"} },
152
153	{ "rr_pco_use rpu_uselen", EXISTS, ICMP6_H, "rr_pco_use",
154		"rpu_uselen", "0", {"1"} },
155	{ "rr_pco_use rpu_keeplen", EXISTS, ICMP6_H, "rr_pco_use",
156		"rpu_keeplen", "1", {"1"} },
157	{ "rr_pco_use rpu_ramask", EXISTS, ICMP6_H, "rr_pco_use",
158		"rpu_ramask", "2", {"1"} },
159	{ "rr_pco_use rpu_raflags", EXISTS, ICMP6_H, "rr_pco_use",
160		"rpu_raflags", "3", {"1"} },
161	{ "rr_pco_use rpu_vltime", EXISTS, ICMP6_H, "rr_pco_use",
162		"rpu_vltime", "4", {"4"} },
163	{ "rr_pco_use rpu_pltime", EXISTS, ICMP6_H, "rr_pco_use",
164		"rpu_pltime", "8", {"4"} },
165	{ "rr_pco_use rpu_flags", EXISTS, ICMP6_H, "rr_pco_use",
166		"rpu_flags", "12", {"4"} },
167	{ "rr_pco_use rpu_prefix", EXISTS, ICMP6_H, "rr_pco_use",
168		"rpu_prefix", "16", {"sizeof(struct in6_addr)"} },
169
170	{ "ICMP6_RR_PCOUSE_RAFLAGS_ONLINK", VALUE, ICMP6_H,
171		"ICMP6_RR_PCOUSE_RAFLAGS_ONLINK", NULL, NULL, {"0x20"} },
172	{ "ICMP6_RR_PCOUSE_RAFLAGS_AUTO", VALUE, ICMP6_H,
173		"ICMP6_RR_PCOUSE_RAFLAGS_AUTO", NULL, NULL, {"0x10"} },
174	{ "ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME", VALUE, ICMP6_H,
175		"ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME", NULL, NULL,
176		{"htonl(0x80000000)"} },
177	{ "ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME", VALUE, ICMP6_H,
178		"ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME", NULL, NULL,
179		{"htonl(0x40000000)"} },
180
181	{ "rr_result rrr_flags", EXISTS, ICMP6_H, "rr_result",
182		"rrr_flags", "0", {"2"} },
183	{ "rr_result rrr_ordinal", EXISTS, ICMP6_H, "rr_result",
184		"rrr_ordinal", "2", {"1"} },
185	{ "rr_result rrr_matchedlen", EXISTS, ICMP6_H, "rr_result",
186		"rrr_matchedlen", "3", {"1"} },
187	{ "rr_result rrr_ifid", EXISTS, ICMP6_H, "rr_result",
188		"rrr_ifid", "4", {"4"} },
189	{ "rr_result rrr_prefix", EXISTS, ICMP6_H, "rr_result",
190		"rrr_prefix", "8", {"sizeof(struct in6_addr)"} },
191
192	{ "ICMP6_RR_RESULT_FLAGS_OOB", VALUE, ICMP6_H,
193		"ICMP6_RR_RESULT_FLAGS_OOB", NULL, NULL,
194		{"htons(0x0002)"} },
195	{ "ICMP6_RR_RESULT_FLAGS_FORBIDDEN", VALUE, ICMP6_H,
196		"ICMP6_RR_RESULT_FLAGS_FORBIDDEN", NULL, NULL,
197		{"htons(0x0001)"} },
198};
199
200#define FTCOUNT	(sizeof(ftab)/sizeof(ftab[0]))
201
202int TST_TOTAL = FTCOUNT;
203
204int
205main(int argc, char *argv[])
206{
207	int	i, lc;
208	char *msg;
209
210	/* Parse standard options given to run the test. */
211	msg = parse_opts(argc, argv, NULL, NULL);
212	if (msg != NULL) {
213		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
214	}
215
216	setup();
217
218	for (lc = 0; TEST_LOOPING(lc); ++lc) {
219		for (i=0; i<FTCOUNT; ++i) {
220			switch (ftab[i].ft_type) {
221			case EXISTS:
222				structcheck(ftab[i].ft_tname, ftab[i].ft_incl,
223					ftab[i].ft_struct, ftab[i].ft_field,
224					ftab[i].ft_offset, ftab[i].ft_value);
225				break;
226			case ALIAS:
227				aliascheck(ftab[i].ft_tname, ftab[i].ft_incl,
228					ftab[i].ft_struct, ftab[i].ft_field,
229					ftab[i].ft_dname);
230				break;
231			case VALUE:
232				valuecheck(ftab[i].ft_tname, ftab[i].ft_incl,
233					ftab[i].ft_struct, ftab[i].ft_dname);
234				break;
235			default:
236				tst_resm(TBROK, "invalid type %d",
237					ftab[i].ft_type);
238				break;
239			}
240		}
241	}
242
243	cleanup();
244	/* NOTREACHED */
245	return 0;
246}
247
248void
249setup(void)
250{
251	TEST_PAUSE;	/* if -P option specified */
252}
253
254void
255cleanup(void)
256{
257	TEST_CLEANUP;
258	tst_exit();
259}
260
261