1*10616SSebastien.Roy@Sun.COM /*
2*10616SSebastien.Roy@Sun.COM * CDDL HEADER START
3*10616SSebastien.Roy@Sun.COM *
4*10616SSebastien.Roy@Sun.COM * The contents of this file are subject to the terms of the
5*10616SSebastien.Roy@Sun.COM * Common Development and Distribution License (the "License").
6*10616SSebastien.Roy@Sun.COM * You may not use this file except in compliance with the License.
7*10616SSebastien.Roy@Sun.COM *
8*10616SSebastien.Roy@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*10616SSebastien.Roy@Sun.COM * or http://www.opensolaris.org/os/licensing.
10*10616SSebastien.Roy@Sun.COM * See the License for the specific language governing permissions
11*10616SSebastien.Roy@Sun.COM * and limitations under the License.
12*10616SSebastien.Roy@Sun.COM *
13*10616SSebastien.Roy@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
14*10616SSebastien.Roy@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*10616SSebastien.Roy@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
16*10616SSebastien.Roy@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
17*10616SSebastien.Roy@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
18*10616SSebastien.Roy@Sun.COM *
19*10616SSebastien.Roy@Sun.COM * CDDL HEADER END
20*10616SSebastien.Roy@Sun.COM */
21*10616SSebastien.Roy@Sun.COM /*
22*10616SSebastien.Roy@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23*10616SSebastien.Roy@Sun.COM * Use is subject to license terms.
24*10616SSebastien.Roy@Sun.COM */
25*10616SSebastien.Roy@Sun.COM
26*10616SSebastien.Roy@Sun.COM /*
27*10616SSebastien.Roy@Sun.COM * This file implements the ioctl control path for the iptun driver. The
28*10616SSebastien.Roy@Sun.COM * GLDv3 dld_ioc_register() mechanism is used to register iptun ioctls with
29*10616SSebastien.Roy@Sun.COM * the dld module.
30*10616SSebastien.Roy@Sun.COM */
31*10616SSebastien.Roy@Sun.COM
32*10616SSebastien.Roy@Sun.COM #include <sys/dld_ioc.h>
33*10616SSebastien.Roy@Sun.COM #include <sys/policy.h>
34*10616SSebastien.Roy@Sun.COM #include <inet/iptun.h>
35*10616SSebastien.Roy@Sun.COM #include "iptun_impl.h"
36*10616SSebastien.Roy@Sun.COM
37*10616SSebastien.Roy@Sun.COM /* ARGSUSED */
38*10616SSebastien.Roy@Sun.COM static int
iptun_ioc_create(void * karg,intptr_t arg,int mode,cred_t * cred,int * rvalp)39*10616SSebastien.Roy@Sun.COM iptun_ioc_create(void *karg, intptr_t arg, int mode, cred_t *cred, int *rvalp)
40*10616SSebastien.Roy@Sun.COM {
41*10616SSebastien.Roy@Sun.COM return (iptun_create(karg, cred));
42*10616SSebastien.Roy@Sun.COM }
43*10616SSebastien.Roy@Sun.COM
44*10616SSebastien.Roy@Sun.COM /* ARGSUSED */
45*10616SSebastien.Roy@Sun.COM static int
iptun_ioc_delete(void * karg,intptr_t arg,int mode,cred_t * cred,int * rvalp)46*10616SSebastien.Roy@Sun.COM iptun_ioc_delete(void *karg, intptr_t arg, int mode, cred_t *cred, int *rvalp)
47*10616SSebastien.Roy@Sun.COM {
48*10616SSebastien.Roy@Sun.COM return (iptun_delete(*(datalink_id_t *)karg, cred));
49*10616SSebastien.Roy@Sun.COM }
50*10616SSebastien.Roy@Sun.COM
51*10616SSebastien.Roy@Sun.COM /* ARGSUSED */
52*10616SSebastien.Roy@Sun.COM static int
iptun_ioc_modify(void * karg,intptr_t arg,int mode,cred_t * cred,int * rvalp)53*10616SSebastien.Roy@Sun.COM iptun_ioc_modify(void *karg, intptr_t arg, int mode, cred_t *cred, int *rvalp)
54*10616SSebastien.Roy@Sun.COM {
55*10616SSebastien.Roy@Sun.COM return (iptun_modify(karg, cred));
56*10616SSebastien.Roy@Sun.COM }
57*10616SSebastien.Roy@Sun.COM
58*10616SSebastien.Roy@Sun.COM /* ARGSUSED */
59*10616SSebastien.Roy@Sun.COM static int
iptun_ioc_info(void * karg,intptr_t arg,int mode,cred_t * cred,int * rvalp)60*10616SSebastien.Roy@Sun.COM iptun_ioc_info(void *karg, intptr_t arg, int mode, cred_t *cred, int *rvalp)
61*10616SSebastien.Roy@Sun.COM {
62*10616SSebastien.Roy@Sun.COM return (iptun_info(karg, cred));
63*10616SSebastien.Roy@Sun.COM }
64*10616SSebastien.Roy@Sun.COM
65*10616SSebastien.Roy@Sun.COM /* ARGSUSED */
66*10616SSebastien.Roy@Sun.COM static int
iptun_ioc_set_6to4relay(void * karg,intptr_t arg,int mode,cred_t * cred,int * rvalp)67*10616SSebastien.Roy@Sun.COM iptun_ioc_set_6to4relay(void *karg, intptr_t arg, int mode, cred_t *cred,
68*10616SSebastien.Roy@Sun.COM int *rvalp)
69*10616SSebastien.Roy@Sun.COM {
70*10616SSebastien.Roy@Sun.COM ipaddr_t *relay = karg;
71*10616SSebastien.Roy@Sun.COM netstack_t *ns = netstack_find_by_cred(cred);
72*10616SSebastien.Roy@Sun.COM int err;
73*10616SSebastien.Roy@Sun.COM
74*10616SSebastien.Roy@Sun.COM err = iptun_set_6to4relay(ns, *relay);
75*10616SSebastien.Roy@Sun.COM netstack_rele(ns);
76*10616SSebastien.Roy@Sun.COM return (err);
77*10616SSebastien.Roy@Sun.COM }
78*10616SSebastien.Roy@Sun.COM
79*10616SSebastien.Roy@Sun.COM /* ARGSUSED */
80*10616SSebastien.Roy@Sun.COM static int
iptun_ioc_get_6to4relay(void * karg,intptr_t arg,int mode,cred_t * cred,int * rvalp)81*10616SSebastien.Roy@Sun.COM iptun_ioc_get_6to4relay(void *karg, intptr_t arg, int mode, cred_t *cred,
82*10616SSebastien.Roy@Sun.COM int *rvalp)
83*10616SSebastien.Roy@Sun.COM {
84*10616SSebastien.Roy@Sun.COM ipaddr_t *relay = karg;
85*10616SSebastien.Roy@Sun.COM netstack_t *ns = netstack_find_by_cred(cred);
86*10616SSebastien.Roy@Sun.COM
87*10616SSebastien.Roy@Sun.COM iptun_get_6to4relay(ns, relay);
88*10616SSebastien.Roy@Sun.COM netstack_rele(ns);
89*10616SSebastien.Roy@Sun.COM return (0);
90*10616SSebastien.Roy@Sun.COM }
91*10616SSebastien.Roy@Sun.COM
92*10616SSebastien.Roy@Sun.COM static dld_ioc_info_t iptun_ioc_list[] = {
93*10616SSebastien.Roy@Sun.COM { IPTUN_CREATE, DLDCOPYIN, sizeof (iptun_kparams_t),
94*10616SSebastien.Roy@Sun.COM iptun_ioc_create, secpolicy_iptun_config},
95*10616SSebastien.Roy@Sun.COM { IPTUN_DELETE, DLDCOPYIN, sizeof (datalink_id_t),
96*10616SSebastien.Roy@Sun.COM iptun_ioc_delete, secpolicy_iptun_config},
97*10616SSebastien.Roy@Sun.COM { IPTUN_MODIFY, DLDCOPYIN, sizeof (iptun_kparams_t),
98*10616SSebastien.Roy@Sun.COM iptun_ioc_modify, secpolicy_iptun_config},
99*10616SSebastien.Roy@Sun.COM { IPTUN_INFO, DLDCOPYINOUT, sizeof (iptun_kparams_t),
100*10616SSebastien.Roy@Sun.COM iptun_ioc_info, NULL},
101*10616SSebastien.Roy@Sun.COM { IPTUN_SET_6TO4RELAY, DLDCOPYIN, sizeof (struct in_addr),
102*10616SSebastien.Roy@Sun.COM iptun_ioc_set_6to4relay, secpolicy_iptun_config},
103*10616SSebastien.Roy@Sun.COM { IPTUN_GET_6TO4RELAY, DLDCOPYINOUT, sizeof (struct in_addr),
104*10616SSebastien.Roy@Sun.COM iptun_ioc_get_6to4relay, NULL}
105*10616SSebastien.Roy@Sun.COM };
106*10616SSebastien.Roy@Sun.COM
107*10616SSebastien.Roy@Sun.COM int
iptun_ioc_init(void)108*10616SSebastien.Roy@Sun.COM iptun_ioc_init(void)
109*10616SSebastien.Roy@Sun.COM {
110*10616SSebastien.Roy@Sun.COM return (dld_ioc_register(IPTUN_IOC, iptun_ioc_list,
111*10616SSebastien.Roy@Sun.COM DLDIOCCNT(iptun_ioc_list)));
112*10616SSebastien.Roy@Sun.COM }
113*10616SSebastien.Roy@Sun.COM
114*10616SSebastien.Roy@Sun.COM void
iptun_ioc_fini(void)115*10616SSebastien.Roy@Sun.COM iptun_ioc_fini(void)
116*10616SSebastien.Roy@Sun.COM {
117*10616SSebastien.Roy@Sun.COM dld_ioc_unregister(IPTUN_IOC);
118*10616SSebastien.Roy@Sun.COM }
119