blob: 14d1736db050143762667ad32de11edb29db7799 [file] [log] [blame]
mridge949c5b12006-01-03 23:01:28 +00001/*
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
mridge949c5b12006-01-03 23:01:28 +000018 */
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"
mridge949c5b12006-01-03 23:01:28 +000047#include "runcc.h"
48
Wanlong Gao354ebb42012-12-07 10:10:04 +080049char *TCID = "asapi_03"; /* Test program identifier. */
mridge949c5b12006-01-03 23:01:28 +000050
51void setup(void), cleanup(void);
52
53enum ttype { EXISTS, ALIAS, VALUE };
54
55struct ftent {
Wanlong Gao354ebb42012-12-07 10:10:04 +080056 char *ft_tname; /* test name */
57 int ft_type; /* test type */
58 char *ft_incl; /* include file list */
59 char *ft_struct; /* structure name */
60 char *ft_field; /* field name */
61 char *ft_offset; /* field offset */
mridge949c5b12006-01-03 23:01:28 +000062 union {
Wanlong Gao354ebb42012-12-07 10:10:04 +080063 char *fu_value; /* field size or value */
64 char *fu_dname; /* #define name */
mridge949c5b12006-01-03 23:01:28 +000065 } ftun;
66#define ft_value ftun.fu_value
67#define ft_dname ftun.fu_dname
68} ftab[] = {
69/* section 2.2.3, MLDv1 */
Wanlong Gao354ebb42012-12-07 10:10:04 +080070 {
71 "MLD_LISTENER_QUERY", VALUE, ICMP6_H, "MLD_LISTENER_QUERY",
72 NULL, NULL, {
73 "130"}}, {
74 "MLD_LISTENER_REPORT", VALUE, ICMP6_H, "MLD_LISTENER_REPORT",
75 NULL, NULL, {
76 "131"}}, {
77 "MLD_LISTENER_REDUCTION", VALUE, ICMP6_H,
78 "MLD_LISTENER_REDUCTION", NULL, NULL, {
79 "132"}}, {
80 "mld_hdr mld_icmp6_hdr", EXISTS, ICMP6_H, "mld_hdr",
81 "mld_icmp6_hdr", "0", {
82 "sizeof(struct icmp6_hdr)"}}, {
83 "mld_hdr mld_addr", EXISTS, ICMP6_H, "mld_hdr", "mld_addr",
84 "sizeof(struct icmp6_hdr)", {
85 "sizeof(struct in6_addr)"}}, {
86 "mld_hdr mld_type define", ALIAS, ICMP6_H, "mld_hdr",
87 "mld_icmp6_hdr.icmp6_type", NULL, {
88 "mld_type"}}, {
89 "mld_hdr mld_code define", ALIAS, ICMP6_H, "mld_hdr",
90 "mld_icmp6_hdr.icmp6_code", NULL, {
91 "mld_code"}}, {
92 "mld_hdr mld_cksum define", ALIAS, ICMP6_H, "mld_hdr",
93 "mld_icmp6_hdr.icmp6_cksum", NULL, {
94 "mld_cksum"}}, {
95 "mld_hdr mld_maxdelay define", ALIAS, ICMP6_H, "mld_hdr",
96 "mld_icmp6_hdr.icmp6_data16[0]", NULL, {
97 "mld_maxdelay"}}, {
98 "mld_hdr mld_reserved define", ALIAS, ICMP6_H, "mld_hdr",
99 "mld_icmp6_hdr.icmp6_data16[1]", NULL, {
100 "mld_reserved"}},
mridge949c5b12006-01-03 23:01:28 +0000101/* section 2.2.4, Router renumbering */
Wanlong Gao354ebb42012-12-07 10:10:04 +0800102 {
103 "ICMP6_ROUTER_RENUMBERING", VALUE, ICMP6_H,
104 "ICMP6_ROUTER_RENUMBERING", NULL, NULL, {
105 "138"}}, {
106 "icmp6_router_renum rr_hdr", EXISTS, ICMP6_H,
107 "icmp6_router_renum", "rr_hdr", "0", {
108 "sizeof(struct icmp6_hdr)"}}, {
109 "icmp6_router_renum rr_segnum", EXISTS, ICMP6_H,
110 "icmp6_router_renum", "rr_segnum",
111 "sizeof(struct icmp6_hdr)", {
112 "1"}}, {
113 "icmp6_router_renum rr_flags", EXISTS, ICMP6_H,
114 "icmp6_router_renum", "rr_flags",
115 "sizeof(struct icmp6_hdr)+1", {
116 "1"}}, {
117 "icmp6_router_renum rr_maxdelay", EXISTS, ICMP6_H,
118 "icmp6_router_renum", "rr_maxdelay",
119 "sizeof(struct icmp6_hdr)+2", {
120 "2"}}, {
121 "icmp6_router_renum rr_reserved", EXISTS, ICMP6_H,
122 "icmp6_router_renum", "rr_reserved",
123 "sizeof(struct icmp6_hdr)+4", {
124 "4"}}, {
125 "icmp6_router_renum rr_type define", ALIAS, ICMP6_H,
126 "icmp6_router_renum", "rr_hdr.icmp6_type", NULL, {
127 "rr_type"}}, {
128 "icmp6_router_renum rr_code define", ALIAS, ICMP6_H,
129 "icmp6_router_renum", "rr_hdr.icmp6_code", NULL, {
130 "rr_code"}}, {
131 "icmp6_router_renum rr_cksum define", ALIAS, ICMP6_H,
132 "icmp6_router_renum", "rr_hdr.icmp6_cksum", NULL, {
133 "rr_cksum"}}, {
134 "icmp6_router_renum rr_seqnum define", ALIAS, ICMP6_H,
135 "icmp6_router_renum", "rr_hdr.icmp6_data32[0]", NULL, {
136 "rr_seqnum"}}, {
137 "ICMP6_RR_FLAGS_TEST", VALUE, ICMP6_H, "ICMP6_RR_FLAGS_TEST",
138 NULL, NULL, {
139 "0x80"}}, {
140 "ICMP6_RR_FLAGS_REQRESULT", VALUE, ICMP6_H,
141 "ICMP6_RR_FLAGS_REQRESULT", NULL, NULL, {
142 "0x40"}}, {
143 "ICMP6_RR_FLAGS_FORCEAPPLY", VALUE, ICMP6_H,
144 "ICMP6_RR_FLAGS_FORCEAPPLY", NULL, NULL, {
145 "0x20"}}, {
146 "ICMP6_RR_FLAGS_SPECSITE", VALUE, ICMP6_H,
147 "ICMP6_RR_FLAGS_SPECSITE", NULL, NULL, {
148 "0x10"}}, {
149 "ICMP6_RR_FLAGS_PREVDONE", VALUE, ICMP6_H,
150 "ICMP6_RR_FLAGS_PREVDONE", NULL, NULL, {
151 "0x08"}}, {
152 "rr_pco_match rpm_code", EXISTS, ICMP6_H, "rr_pco_match",
153 "rpm_code", "0", {
154 "1"}}, {
155 "rr_pco_match rpm_len", EXISTS, ICMP6_H, "rr_pco_match",
156 "rpm_len", "1", {
157 "1"}}, {
158 "rr_pco_match rpm_ordinal", EXISTS, ICMP6_H, "rr_pco_match",
159 "rpm_ordinal", "2", {
160 "1"}}, {
161 "rr_pco_match rpm_matchlen", EXISTS, ICMP6_H, "rr_pco_match",
162 "rpm_matchlen", "3", {
163 "1"}}, {
164 "rr_pco_match rpm_minlen", EXISTS, ICMP6_H, "rr_pco_match",
165 "rpm_minlen", "4", {
166 "1"}}, {
167 "rr_pco_match rpm_maxlen", EXISTS, ICMP6_H, "rr_pco_match",
168 "rpm_maxlen", "5", {
169 "1"}}, {
170 "rr_pco_match rpm_reserved", EXISTS, ICMP6_H, "rr_pco_match",
171 "rpm_reserved", "6", {
172 "2"}}, {
173 "rr_pco_match rpm_prefix", EXISTS, ICMP6_H, "rr_pco_match",
174 "rpm_prefix", "8", {
175 "sizeof(struct in6_addr)"}}, {
176 "RPM_PCO_ADD", VALUE, ICMP6_H, "RPM_PCO_ADD", NULL, NULL, {
177 "1"}}, {
178 "RPM_PCO_CHANGE", VALUE, ICMP6_H, "RPM_PCO_CHANGE", NULL, NULL, {
179 "2"}}, {
180 "RPM_PCO_SETGLOBAL", VALUE, ICMP6_H, "RPM_PCO_SETGLOBAL", NULL,
181 NULL, {
182 "3"}}, {
183 "rr_pco_use rpu_uselen", EXISTS, ICMP6_H, "rr_pco_use",
184 "rpu_uselen", "0", {
185 "1"}}, {
186 "rr_pco_use rpu_keeplen", EXISTS, ICMP6_H, "rr_pco_use",
187 "rpu_keeplen", "1", {
188 "1"}}, {
189 "rr_pco_use rpu_ramask", EXISTS, ICMP6_H, "rr_pco_use",
190 "rpu_ramask", "2", {
191 "1"}}, {
192 "rr_pco_use rpu_raflags", EXISTS, ICMP6_H, "rr_pco_use",
193 "rpu_raflags", "3", {
194 "1"}}, {
195 "rr_pco_use rpu_vltime", EXISTS, ICMP6_H, "rr_pco_use",
196 "rpu_vltime", "4", {
197 "4"}}, {
198 "rr_pco_use rpu_pltime", EXISTS, ICMP6_H, "rr_pco_use",
199 "rpu_pltime", "8", {
200 "4"}}, {
201 "rr_pco_use rpu_flags", EXISTS, ICMP6_H, "rr_pco_use",
202 "rpu_flags", "12", {
203 "4"}}, {
204 "rr_pco_use rpu_prefix", EXISTS, ICMP6_H, "rr_pco_use",
205 "rpu_prefix", "16", {
206 "sizeof(struct in6_addr)"}}, {
207 "ICMP6_RR_PCOUSE_RAFLAGS_ONLINK", VALUE, ICMP6_H,
208 "ICMP6_RR_PCOUSE_RAFLAGS_ONLINK", NULL, NULL, {
209 "0x20"}}, {
210 "ICMP6_RR_PCOUSE_RAFLAGS_AUTO", VALUE, ICMP6_H,
211 "ICMP6_RR_PCOUSE_RAFLAGS_AUTO", NULL, NULL, {
212 "0x10"}}, {
213 "ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME", VALUE, ICMP6_H,
214 "ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME", NULL, NULL, {
215 "htonl(0x80000000)"}}, {
216 "ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME", VALUE, ICMP6_H,
217 "ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME", NULL, NULL, {
218 "htonl(0x40000000)"}}, {
219 "rr_result rrr_flags", EXISTS, ICMP6_H, "rr_result",
220 "rrr_flags", "0", {
221 "2"}}, {
222 "rr_result rrr_ordinal", EXISTS, ICMP6_H, "rr_result",
223 "rrr_ordinal", "2", {
224 "1"}}, {
225 "rr_result rrr_matchedlen", EXISTS, ICMP6_H, "rr_result",
226 "rrr_matchedlen", "3", {
227 "1"}}, {
228 "rr_result rrr_ifid", EXISTS, ICMP6_H, "rr_result",
229 "rrr_ifid", "4", {
230 "4"}}, {
231 "rr_result rrr_prefix", EXISTS, ICMP6_H, "rr_result",
232 "rrr_prefix", "8", {
233 "sizeof(struct in6_addr)"}}, {
234 "ICMP6_RR_RESULT_FLAGS_OOB", VALUE, ICMP6_H,
235 "ICMP6_RR_RESULT_FLAGS_OOB", NULL, NULL, {
236 "htons(0x0002)"}}, {
237 "ICMP6_RR_RESULT_FLAGS_FORBIDDEN", VALUE, ICMP6_H,
238 "ICMP6_RR_RESULT_FLAGS_FORBIDDEN", NULL, NULL, {
239"htons(0x0001)"}},};
mridge949c5b12006-01-03 23:01:28 +0000240
241#define FTCOUNT (sizeof(ftab)/sizeof(ftab[0]))
242
243int TST_TOTAL = FTCOUNT;
244
Wanlong Gao354ebb42012-12-07 10:10:04 +0800245int main(int argc, char *argv[])
mridge949c5b12006-01-03 23:01:28 +0000246{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800247 int i, lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200248 const char *msg;
mridge949c5b12006-01-03 23:01:28 +0000249
250 /* Parse standard options given to run the test. */
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800251 msg = parse_opts(argc, argv, NULL, NULL);
252 if (msg != NULL) {
Garrett Cooper53740502010-12-16 00:04:01 -0800253 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
mridge949c5b12006-01-03 23:01:28 +0000254 }
255
256 setup();
257
258 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800259 for (i = 0; i < FTCOUNT; ++i) {
mridge949c5b12006-01-03 23:01:28 +0000260 switch (ftab[i].ft_type) {
261 case EXISTS:
262 structcheck(ftab[i].ft_tname, ftab[i].ft_incl,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800263 ftab[i].ft_struct, ftab[i].ft_field,
264 ftab[i].ft_offset,
265 ftab[i].ft_value);
mridge949c5b12006-01-03 23:01:28 +0000266 break;
267 case ALIAS:
268 aliascheck(ftab[i].ft_tname, ftab[i].ft_incl,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800269 ftab[i].ft_struct, ftab[i].ft_field,
270 ftab[i].ft_dname);
mridge949c5b12006-01-03 23:01:28 +0000271 break;
272 case VALUE:
273 valuecheck(ftab[i].ft_tname, ftab[i].ft_incl,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800274 ftab[i].ft_struct, ftab[i].ft_dname);
mridge949c5b12006-01-03 23:01:28 +0000275 break;
276 default:
277 tst_resm(TBROK, "invalid type %d",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800278 ftab[i].ft_type);
mridge949c5b12006-01-03 23:01:28 +0000279 break;
280 }
281 }
282 }
283
284 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -0800285
286 tst_exit();
mridge949c5b12006-01-03 23:01:28 +0000287}
288
Wanlong Gao354ebb42012-12-07 10:10:04 +0800289void setup(void)
mridge949c5b12006-01-03 23:01:28 +0000290{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800291 TEST_PAUSE; /* if -P option specified */
mridge949c5b12006-01-03 23:01:28 +0000292}
293
Wanlong Gao354ebb42012-12-07 10:10:04 +0800294void cleanup(void)
mridge949c5b12006-01-03 23:01:28 +0000295{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700296}