asapi_03.c revision 0b9589f3f9c0345b29cfcf7da5a1253c708303eb
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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	{
72		"MLD_LISTENER_QUERY", VALUE, ICMP6_H, "MLD_LISTENER_QUERY",
73		    NULL, NULL, {
74	"130"}}, {
75		"MLD_LISTENER_REPORT", VALUE, ICMP6_H, "MLD_LISTENER_REPORT",
76		    NULL, NULL, {
77	"131"}}, {
78		"MLD_LISTENER_REDUCTION", VALUE, ICMP6_H,
79		    "MLD_LISTENER_REDUCTION", NULL, NULL, {
80	"132"}}, {
81		"mld_hdr mld_icmp6_hdr", EXISTS, ICMP6_H, "mld_hdr",
82		    "mld_icmp6_hdr", "0", {
83	"sizeof(struct icmp6_hdr)"}}, {
84		"mld_hdr mld_addr", EXISTS, ICMP6_H, "mld_hdr", "mld_addr",
85		    "sizeof(struct icmp6_hdr)", {
86	"sizeof(struct in6_addr)"}}, {
87		"mld_hdr mld_type define", ALIAS, ICMP6_H, "mld_hdr",
88		    "mld_icmp6_hdr.icmp6_type", NULL, {
89	"mld_type"}}, {
90		"mld_hdr mld_code define", ALIAS, ICMP6_H, "mld_hdr",
91		    "mld_icmp6_hdr.icmp6_code", NULL, {
92	"mld_code"}}, {
93		"mld_hdr mld_cksum define", ALIAS, ICMP6_H, "mld_hdr",
94		    "mld_icmp6_hdr.icmp6_cksum", NULL, {
95	"mld_cksum"}}, {
96		"mld_hdr mld_maxdelay define", ALIAS, ICMP6_H, "mld_hdr",
97		    "mld_icmp6_hdr.icmp6_data16[0]", NULL, {
98	"mld_maxdelay"}}, {
99		"mld_hdr mld_reserved define", ALIAS, ICMP6_H, "mld_hdr",
100		    "mld_icmp6_hdr.icmp6_data16[1]", NULL, {
101	"mld_reserved"}},
102/* section 2.2.4, Router renumbering */
103	{
104		"ICMP6_ROUTER_RENUMBERING", VALUE, ICMP6_H,
105		    "ICMP6_ROUTER_RENUMBERING", NULL, NULL, {
106	"138"}}, {
107		"icmp6_router_renum rr_hdr", EXISTS, ICMP6_H,
108		    "icmp6_router_renum", "rr_hdr", "0", {
109	"sizeof(struct icmp6_hdr)"}}, {
110		"icmp6_router_renum rr_segnum", EXISTS, ICMP6_H,
111		    "icmp6_router_renum", "rr_segnum",
112		    "sizeof(struct icmp6_hdr)", {
113	"1"}}, {
114		"icmp6_router_renum rr_flags", EXISTS, ICMP6_H,
115		    "icmp6_router_renum", "rr_flags",
116		    "sizeof(struct icmp6_hdr)+1", {
117	"1"}}, {
118		"icmp6_router_renum rr_maxdelay", EXISTS, ICMP6_H,
119		    "icmp6_router_renum", "rr_maxdelay",
120		    "sizeof(struct icmp6_hdr)+2", {
121	"2"}}, {
122		"icmp6_router_renum rr_reserved", EXISTS, ICMP6_H,
123		    "icmp6_router_renum", "rr_reserved",
124		    "sizeof(struct icmp6_hdr)+4", {
125	"4"}}, {
126		"icmp6_router_renum rr_type define", ALIAS, ICMP6_H,
127		    "icmp6_router_renum", "rr_hdr.icmp6_type", NULL, {
128	"rr_type"}}, {
129		"icmp6_router_renum rr_code define", ALIAS, ICMP6_H,
130		    "icmp6_router_renum", "rr_hdr.icmp6_code", NULL, {
131	"rr_code"}}, {
132		"icmp6_router_renum rr_cksum define", ALIAS, ICMP6_H,
133		    "icmp6_router_renum", "rr_hdr.icmp6_cksum", NULL, {
134	"rr_cksum"}}, {
135		"icmp6_router_renum rr_seqnum define", ALIAS, ICMP6_H,
136		    "icmp6_router_renum", "rr_hdr.icmp6_data32[0]", NULL, {
137	"rr_seqnum"}}, {
138		"ICMP6_RR_FLAGS_TEST", VALUE, ICMP6_H, "ICMP6_RR_FLAGS_TEST",
139		    NULL, NULL, {
140	"0x80"}}, {
141		"ICMP6_RR_FLAGS_REQRESULT", VALUE, ICMP6_H,
142		    "ICMP6_RR_FLAGS_REQRESULT", NULL, NULL, {
143	"0x40"}}, {
144		"ICMP6_RR_FLAGS_FORCEAPPLY", VALUE, ICMP6_H,
145		    "ICMP6_RR_FLAGS_FORCEAPPLY", NULL, NULL, {
146	"0x20"}}, {
147		"ICMP6_RR_FLAGS_SPECSITE", VALUE, ICMP6_H,
148		    "ICMP6_RR_FLAGS_SPECSITE", NULL, NULL, {
149	"0x10"}}, {
150		"ICMP6_RR_FLAGS_PREVDONE", VALUE, ICMP6_H,
151		    "ICMP6_RR_FLAGS_PREVDONE", NULL, NULL, {
152	"0x08"}}, {
153		"rr_pco_match rpm_code", EXISTS, ICMP6_H, "rr_pco_match",
154		    "rpm_code", "0", {
155	"1"}}, {
156		"rr_pco_match rpm_len", EXISTS, ICMP6_H, "rr_pco_match",
157		    "rpm_len", "1", {
158	"1"}}, {
159		"rr_pco_match rpm_ordinal", EXISTS, ICMP6_H, "rr_pco_match",
160		    "rpm_ordinal", "2", {
161	"1"}}, {
162		"rr_pco_match rpm_matchlen", EXISTS, ICMP6_H, "rr_pco_match",
163		    "rpm_matchlen", "3", {
164	"1"}}, {
165		"rr_pco_match rpm_minlen", EXISTS, ICMP6_H, "rr_pco_match",
166		    "rpm_minlen", "4", {
167	"1"}}, {
168		"rr_pco_match rpm_maxlen", EXISTS, ICMP6_H, "rr_pco_match",
169		    "rpm_maxlen", "5", {
170	"1"}}, {
171		"rr_pco_match rpm_reserved", EXISTS, ICMP6_H, "rr_pco_match",
172		    "rpm_reserved", "6", {
173	"2"}}, {
174		"rr_pco_match rpm_prefix", EXISTS, ICMP6_H, "rr_pco_match",
175		    "rpm_prefix", "8", {
176	"sizeof(struct in6_addr)"}}, {
177		"RPM_PCO_ADD", VALUE, ICMP6_H, "RPM_PCO_ADD", NULL, NULL, {
178	"1"}}, {
179		"RPM_PCO_CHANGE", VALUE, ICMP6_H, "RPM_PCO_CHANGE", NULL, NULL, {
180	"2"}}, {
181		"RPM_PCO_SETGLOBAL", VALUE, ICMP6_H, "RPM_PCO_SETGLOBAL", NULL,
182		    NULL, {
183	"3"}}, {
184		"rr_pco_use rpu_uselen", EXISTS, ICMP6_H, "rr_pco_use",
185		    "rpu_uselen", "0", {
186	"1"}}, {
187		"rr_pco_use rpu_keeplen", EXISTS, ICMP6_H, "rr_pco_use",
188		    "rpu_keeplen", "1", {
189	"1"}}, {
190		"rr_pco_use rpu_ramask", EXISTS, ICMP6_H, "rr_pco_use",
191		    "rpu_ramask", "2", {
192	"1"}}, {
193		"rr_pco_use rpu_raflags", EXISTS, ICMP6_H, "rr_pco_use",
194		    "rpu_raflags", "3", {
195	"1"}}, {
196		"rr_pco_use rpu_vltime", EXISTS, ICMP6_H, "rr_pco_use",
197		    "rpu_vltime", "4", {
198	"4"}}, {
199		"rr_pco_use rpu_pltime", EXISTS, ICMP6_H, "rr_pco_use",
200		    "rpu_pltime", "8", {
201	"4"}}, {
202		"rr_pco_use rpu_flags", EXISTS, ICMP6_H, "rr_pco_use",
203		    "rpu_flags", "12", {
204	"4"}}, {
205		"rr_pco_use rpu_prefix", EXISTS, ICMP6_H, "rr_pco_use",
206		    "rpu_prefix", "16", {
207	"sizeof(struct in6_addr)"}}, {
208		"ICMP6_RR_PCOUSE_RAFLAGS_ONLINK", VALUE, ICMP6_H,
209		    "ICMP6_RR_PCOUSE_RAFLAGS_ONLINK", NULL, NULL, {
210	"0x20"}}, {
211		"ICMP6_RR_PCOUSE_RAFLAGS_AUTO", VALUE, ICMP6_H,
212		    "ICMP6_RR_PCOUSE_RAFLAGS_AUTO", NULL, NULL, {
213	"0x10"}}, {
214		"ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME", VALUE, ICMP6_H,
215		    "ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME", NULL, NULL, {
216	"htonl(0x80000000)"}}, {
217		"ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME", VALUE, ICMP6_H,
218		    "ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME", NULL, NULL, {
219	"htonl(0x40000000)"}}, {
220		"rr_result rrr_flags", EXISTS, ICMP6_H, "rr_result",
221		    "rrr_flags", "0", {
222	"2"}}, {
223		"rr_result rrr_ordinal", EXISTS, ICMP6_H, "rr_result",
224		    "rrr_ordinal", "2", {
225	"1"}}, {
226		"rr_result rrr_matchedlen", EXISTS, ICMP6_H, "rr_result",
227		    "rrr_matchedlen", "3", {
228	"1"}}, {
229		"rr_result rrr_ifid", EXISTS, ICMP6_H, "rr_result",
230		    "rrr_ifid", "4", {
231	"4"}}, {
232		"rr_result rrr_prefix", EXISTS, ICMP6_H, "rr_result",
233		    "rrr_prefix", "8", {
234	"sizeof(struct in6_addr)"}}, {
235		"ICMP6_RR_RESULT_FLAGS_OOB", VALUE, ICMP6_H,
236		    "ICMP6_RR_RESULT_FLAGS_OOB", NULL, NULL, {
237	"htons(0x0002)"}}, {
238		"ICMP6_RR_RESULT_FLAGS_FORBIDDEN", VALUE, ICMP6_H,
239		    "ICMP6_RR_RESULT_FLAGS_FORBIDDEN", NULL, NULL, {
240"htons(0x0001)"}},};
241
242#define FTCOUNT	(sizeof(ftab)/sizeof(ftab[0]))
243
244int TST_TOTAL = FTCOUNT;
245
246int main(int argc, char *argv[])
247{
248	int i, lc;
249	const char *msg;
250
251	/* Parse standard options given to run the test. */
252	msg = parse_opts(argc, argv, NULL, NULL);
253	if (msg != NULL) {
254		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
255	}
256
257	setup();
258
259	for (lc = 0; TEST_LOOPING(lc); ++lc) {
260		for (i = 0; i < FTCOUNT; ++i) {
261			switch (ftab[i].ft_type) {
262			case EXISTS:
263				structcheck(ftab[i].ft_tname, ftab[i].ft_incl,
264					    ftab[i].ft_struct, ftab[i].ft_field,
265					    ftab[i].ft_offset,
266					    ftab[i].ft_value);
267				break;
268			case ALIAS:
269				aliascheck(ftab[i].ft_tname, ftab[i].ft_incl,
270					   ftab[i].ft_struct, ftab[i].ft_field,
271					   ftab[i].ft_dname);
272				break;
273			case VALUE:
274				valuecheck(ftab[i].ft_tname, ftab[i].ft_incl,
275					   ftab[i].ft_struct, ftab[i].ft_dname);
276				break;
277			default:
278				tst_resm(TBROK, "invalid type %d",
279					 ftab[i].ft_type);
280				break;
281			}
282		}
283	}
284
285	cleanup();
286
287	tst_exit();
288}
289
290void setup(void)
291{
292	TEST_PAUSE;		/* if -P option specified */
293}
294
295void cleanup(void)
296{
297	TEST_CLEANUP;
298}
299