2 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <netinet6/in6.h>
38 #include <netkey/keyv2.h>
39 #include <netkey/key_debug.h>
40 #include <netinet6/ipsec.h>
49 "must_error", /* error */
50 "in ipsec must_error", /* error */
51 "out ipsec esp/must_error", /* error */
56 "in bypass", /* may be error */
57 "out ipsec esp", /* error */
58 "in ipsec ah/transport",
59 "in ipsec ah/tunnel", /* error */
60 "out ipsec ah/transport/",
61 "out ipsec ah/tunnel/", /* error */
62 "in ipsec esp / transport / 10.0.0.1-10.0.0.2",
63 "in ipsec esp/tunnel/::1-::2",
64 "in ipsec esp/tunnel/10.0.0.1-::2", /* error */
65 "in ipsec esp/tunnel/::1-::2/require",
66 "out ipsec ah/transport//use",
67 "out ipsec ah/transport esp/use",
68 "in ipsec ah/transport esp/tunnel", /* error */
71 esp / tunnel / ::1-::2",
74 ah/transport/::1-::2 esp/tunnel/::3-::4/use ah/transport/::5-::6/require
75 ah/transport/::1-::2 esp/tunnel/::3-::4/use ah/transport/::5-::6/require
76 ah/transport/::1-::2 esp/tunnel/::3-::4/use ah/transport/::5-::6/require
78 "out ipsec esp/transport/fec0::10-fec0::11/use",
81 int test(char *buf, int family);
97 for (i = 0; i < sizeof(requests)/sizeof(requests[0]); i++) {
98 printf("*** requests ***\n");
99 printf("\t[%s]\n", requests[i]);
101 buf = ipsec_set_policy(requests[i], strlen(requests[i]));
103 printf("ipsec_set_policy: %s\n", ipsec_strerror());
107 printf("\tsetlen:%d\n", ipsec_get_policylen(buf));
110 printf("\tPF_INET:\n");
113 printf("\tPF_INET6:\n");
116 kdebug_sadb_x_policy((struct sadb_ext *)buf);
129 int so, proto, optname;
136 optname = IP_IPSEC_POLICY;
139 proto = IPPROTO_IPV6;
140 optname = IPV6_IPSEC_POLICY;
144 if ((so = socket(family, SOCK_DGRAM, 0)) < 0)
147 len = ipsec_get_policylen(policy);
148 if (setsockopt(so, proto, optname, policy, len) < 0) {
149 printf("error on setsockopt");
153 len = sizeof(getbuf);
154 memset(getbuf, 0, sizeof(getbuf));
155 if (getsockopt(so, proto, optname, getbuf, &len) < 0) {
156 printf("error on getsockopt");
163 printf("\tgetlen:%d\n", len);
165 if ((buf = ipsec_dump_policy(getbuf, NULL)) == NULL) {
166 printf("%s\n", ipsec_strerror());
169 printf("\t[%s]\n", buf);