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