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