1*f4b3ec61Sdh155122 /* 2*f4b3ec61Sdh155122 * CDDL HEADER START 3*f4b3ec61Sdh155122 * 4*f4b3ec61Sdh155122 * The contents of this file are subject to the terms of the 5*f4b3ec61Sdh155122 * Common Development and Distribution License (the "License"). 6*f4b3ec61Sdh155122 * You may not use this file except in compliance with the License. 7*f4b3ec61Sdh155122 * 8*f4b3ec61Sdh155122 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*f4b3ec61Sdh155122 * or http://www.opensolaris.org/os/licensing. 10*f4b3ec61Sdh155122 * See the License for the specific language governing permissions 11*f4b3ec61Sdh155122 * and limitations under the License. 12*f4b3ec61Sdh155122 * 13*f4b3ec61Sdh155122 * When distributing Covered Code, include this CDDL HEADER in each 14*f4b3ec61Sdh155122 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*f4b3ec61Sdh155122 * If applicable, add the following below this CDDL HEADER, with the 16*f4b3ec61Sdh155122 * fields enclosed by brackets "[]" replaced with your own identifying 17*f4b3ec61Sdh155122 * information: Portions Copyright [yyyy] [name of copyright owner] 18*f4b3ec61Sdh155122 * 19*f4b3ec61Sdh155122 * CDDL HEADER END 20*f4b3ec61Sdh155122 */ 21*f4b3ec61Sdh155122 22*f4b3ec61Sdh155122 /* 23*f4b3ec61Sdh155122 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24*f4b3ec61Sdh155122 * Use is subject to license terms. 25*f4b3ec61Sdh155122 */ 26*f4b3ec61Sdh155122 #ifndef _SYS_NETSTACK_H 27*f4b3ec61Sdh155122 #define _SYS_NETSTACK_H 28*f4b3ec61Sdh155122 29*f4b3ec61Sdh155122 #pragma ident "%Z%%M% %I% %E% SMI" 30*f4b3ec61Sdh155122 31*f4b3ec61Sdh155122 #include <sys/kstat.h> 32*f4b3ec61Sdh155122 33*f4b3ec61Sdh155122 #ifdef __cplusplus 34*f4b3ec61Sdh155122 extern "C" { 35*f4b3ec61Sdh155122 #endif 36*f4b3ec61Sdh155122 37*f4b3ec61Sdh155122 /* 38*f4b3ec61Sdh155122 * This allows various pieces in and around IP to have a separate instance 39*f4b3ec61Sdh155122 * for each instance of IP. This is used to support zones that have an 40*f4b3ec61Sdh155122 * exclusive stack. 41*f4b3ec61Sdh155122 * Pieces of software far removed from IP (e.g., kernel software 42*f4b3ec61Sdh155122 * sitting on top of TCP or UDP) probably should not use the netstack 43*f4b3ec61Sdh155122 * support; if such software wants to support separate zones it 44*f4b3ec61Sdh155122 * can do that using the zones framework (zone_key_create() etc) 45*f4b3ec61Sdh155122 * whether there is a shared IP stack or and exclusive IP stack underneath. 46*f4b3ec61Sdh155122 */ 47*f4b3ec61Sdh155122 48*f4b3ec61Sdh155122 /* 49*f4b3ec61Sdh155122 * Each netstack has an identifier. We reuse the zoneid allocation for 50*f4b3ec61Sdh155122 * this but have a separate typedef. Thus the shared stack (used by 51*f4b3ec61Sdh155122 * the global zone and other shared stack zones) have a zero ID, and 52*f4b3ec61Sdh155122 * the exclusive stacks have a netstackid that is the same as their zoneid. 53*f4b3ec61Sdh155122 */ 54*f4b3ec61Sdh155122 typedef id_t netstackid_t; 55*f4b3ec61Sdh155122 56*f4b3ec61Sdh155122 #define GLOBAL_NETSTACKID 0 57*f4b3ec61Sdh155122 58*f4b3ec61Sdh155122 /* 59*f4b3ec61Sdh155122 * One for each module which uses netstack support. 60*f4b3ec61Sdh155122 * Used in netstack_register(). 61*f4b3ec61Sdh155122 * 62*f4b3ec61Sdh155122 * The order of these is important for some modules both for 63*f4b3ec61Sdh155122 * the creation (which done in ascending order) and destruction (which is 64*f4b3ec61Sdh155122 * done ine in decending order). 65*f4b3ec61Sdh155122 */ 66*f4b3ec61Sdh155122 #define NS_HOOK 0 67*f4b3ec61Sdh155122 #define NS_NETI 1 68*f4b3ec61Sdh155122 #define NS_ARP 2 69*f4b3ec61Sdh155122 #define NS_IP 3 70*f4b3ec61Sdh155122 #define NS_ICMP 4 71*f4b3ec61Sdh155122 #define NS_UDP 5 72*f4b3ec61Sdh155122 #define NS_TCP 6 73*f4b3ec61Sdh155122 #define NS_SCTP 7 74*f4b3ec61Sdh155122 #define NS_RTS 8 75*f4b3ec61Sdh155122 #define NS_IPSEC 9 76*f4b3ec61Sdh155122 #define NS_KEYSOCK 10 77*f4b3ec61Sdh155122 #define NS_SPDSOCK 11 78*f4b3ec61Sdh155122 #define NS_IPSECAH 12 79*f4b3ec61Sdh155122 #define NS_IPSECESP 13 80*f4b3ec61Sdh155122 #define NS_TUN 14 81*f4b3ec61Sdh155122 #define NS_IPF 15 82*f4b3ec61Sdh155122 #define NS_STR 16 /* autopush list etc */ 83*f4b3ec61Sdh155122 #define NS_MAX (NS_STR+1) 84*f4b3ec61Sdh155122 85*f4b3ec61Sdh155122 /* 86*f4b3ec61Sdh155122 * One for every netstack in the system. 87*f4b3ec61Sdh155122 * We use a union so that the compilar and lint can provide type checking - 88*f4b3ec61Sdh155122 * in principle we could have 89*f4b3ec61Sdh155122 * #define netstack_arp netstack_modules[NS_ARP] 90*f4b3ec61Sdh155122 * etc, but that would imply void * types hence no type checking by the 91*f4b3ec61Sdh155122 * compiler. 92*f4b3ec61Sdh155122 * 93*f4b3ec61Sdh155122 * All the fields in netstack_t except netstack_next are protected by 94*f4b3ec61Sdh155122 * netstack_lock. netstack_next is protected by netstack_g_lock. 95*f4b3ec61Sdh155122 */ 96*f4b3ec61Sdh155122 struct netstack { 97*f4b3ec61Sdh155122 union { 98*f4b3ec61Sdh155122 void *nu_modules[NS_MAX]; 99*f4b3ec61Sdh155122 struct { 100*f4b3ec61Sdh155122 struct hook_stack *nu_hook; 101*f4b3ec61Sdh155122 struct neti_stack *nu_neti; 102*f4b3ec61Sdh155122 struct arp_stack *nu_arp; 103*f4b3ec61Sdh155122 struct ip_stack *nu_ip; 104*f4b3ec61Sdh155122 struct icmp_stack *nu_icmp; 105*f4b3ec61Sdh155122 struct udp_stack *nu_udp; 106*f4b3ec61Sdh155122 struct tcp_stack *nu_tcp; 107*f4b3ec61Sdh155122 struct sctp_stack *nu_sctp; 108*f4b3ec61Sdh155122 struct rts_stack *nu_rts; 109*f4b3ec61Sdh155122 struct ipsec_stack *nu_ipsec; 110*f4b3ec61Sdh155122 struct keysock_stack *nu_keysock; 111*f4b3ec61Sdh155122 struct spd_stack *nu_spdsock; 112*f4b3ec61Sdh155122 struct ipsecah_stack *nu_ipsecah; 113*f4b3ec61Sdh155122 struct ipsecesp_stack *nu_ipsecesp; 114*f4b3ec61Sdh155122 struct tun_stack *nu_tun; 115*f4b3ec61Sdh155122 struct ipf_stack *nu_ipf; 116*f4b3ec61Sdh155122 struct str_stack *nu_str; 117*f4b3ec61Sdh155122 } nu_s; 118*f4b3ec61Sdh155122 } netstack_u; 119*f4b3ec61Sdh155122 #define netstack_modules netstack_u.nu_modules 120*f4b3ec61Sdh155122 #define netstack_hook netstack_u.nu_s.nu_hook 121*f4b3ec61Sdh155122 #define netstack_neti netstack_u.nu_s.nu_neti 122*f4b3ec61Sdh155122 #define netstack_arp netstack_u.nu_s.nu_arp 123*f4b3ec61Sdh155122 #define netstack_ip netstack_u.nu_s.nu_ip 124*f4b3ec61Sdh155122 #define netstack_icmp netstack_u.nu_s.nu_icmp 125*f4b3ec61Sdh155122 #define netstack_udp netstack_u.nu_s.nu_udp 126*f4b3ec61Sdh155122 #define netstack_tcp netstack_u.nu_s.nu_tcp 127*f4b3ec61Sdh155122 #define netstack_sctp netstack_u.nu_s.nu_sctp 128*f4b3ec61Sdh155122 #define netstack_rts netstack_u.nu_s.nu_rts 129*f4b3ec61Sdh155122 #define netstack_ipsec netstack_u.nu_s.nu_ipsec 130*f4b3ec61Sdh155122 #define netstack_keysock netstack_u.nu_s.nu_keysock 131*f4b3ec61Sdh155122 #define netstack_spdsock netstack_u.nu_s.nu_spdsock 132*f4b3ec61Sdh155122 #define netstack_ipsecah netstack_u.nu_s.nu_ipsecah 133*f4b3ec61Sdh155122 #define netstack_ipsecesp netstack_u.nu_s.nu_ipsecesp 134*f4b3ec61Sdh155122 #define netstack_tun netstack_u.nu_s.nu_tun 135*f4b3ec61Sdh155122 #define netstack_ipf netstack_u.nu_s.nu_ipf 136*f4b3ec61Sdh155122 #define netstack_str netstack_u.nu_s.nu_str 137*f4b3ec61Sdh155122 138*f4b3ec61Sdh155122 uint16_t netstack_m_state[NS_MAX]; /* module state */ 139*f4b3ec61Sdh155122 140*f4b3ec61Sdh155122 kmutex_t netstack_lock; 141*f4b3ec61Sdh155122 struct netstack *netstack_next; 142*f4b3ec61Sdh155122 netstackid_t netstack_stackid; 143*f4b3ec61Sdh155122 int netstack_numzones; /* Number of zones using this */ 144*f4b3ec61Sdh155122 int netstack_refcnt; /* Number of hold-rele */ 145*f4b3ec61Sdh155122 int netstack_flags; /* See below */ 146*f4b3ec61Sdh155122 }; 147*f4b3ec61Sdh155122 typedef struct netstack netstack_t; 148*f4b3ec61Sdh155122 149*f4b3ec61Sdh155122 /* netstack_flags values */ 150*f4b3ec61Sdh155122 #define NSF_UNINIT 0x01 /* Not initialized */ 151*f4b3ec61Sdh155122 #define NSF_CLOSING 0x02 /* Going away */ 152*f4b3ec61Sdh155122 153*f4b3ec61Sdh155122 /* 154*f4b3ec61Sdh155122 * State for each module for each stack - netstack_m_state[moduleid] 155*f4b3ec61Sdh155122 * Keeps track of pending actions to avoid holding looks when 156*f4b3ec61Sdh155122 * calling into the create/shutdown/destroy functions in the module. 157*f4b3ec61Sdh155122 */ 158*f4b3ec61Sdh155122 #define NSS_CREATE_NEEDED 0x0001 159*f4b3ec61Sdh155122 #define NSS_CREATE_INPROGRESS 0x0002 160*f4b3ec61Sdh155122 #define NSS_CREATE_COMPLETED 0x0004 161*f4b3ec61Sdh155122 #define NSS_SHUTDOWN_NEEDED 0x0010 162*f4b3ec61Sdh155122 #define NSS_SHUTDOWN_INPROGRESS 0x0020 163*f4b3ec61Sdh155122 #define NSS_SHUTDOWN_COMPLETED 0x0040 164*f4b3ec61Sdh155122 #define NSS_DESTROY_NEEDED 0x0100 165*f4b3ec61Sdh155122 #define NSS_DESTROY_INPROGRESS 0x0200 166*f4b3ec61Sdh155122 #define NSS_DESTROY_COMPLETED 0x0400 167*f4b3ec61Sdh155122 168*f4b3ec61Sdh155122 #define NSS_CREATE_ALL \ 169*f4b3ec61Sdh155122 (NSS_CREATE_NEEDED|NSS_CREATE_INPROGRESS|NSS_CREATE_COMPLETED) 170*f4b3ec61Sdh155122 #define NSS_SHUTDOWN_ALL \ 171*f4b3ec61Sdh155122 (NSS_SHUTDOWN_NEEDED|NSS_SHUTDOWN_INPROGRESS|NSS_SHUTDOWN_COMPLETED) 172*f4b3ec61Sdh155122 #define NSS_DESTROY_ALL \ 173*f4b3ec61Sdh155122 (NSS_DESTROY_NEEDED|NSS_DESTROY_INPROGRESS|NSS_DESTROY_COMPLETED) 174*f4b3ec61Sdh155122 175*f4b3ec61Sdh155122 /* 176*f4b3ec61Sdh155122 * One for each of the NS_* values. 177*f4b3ec61Sdh155122 */ 178*f4b3ec61Sdh155122 struct netstack_registry { 179*f4b3ec61Sdh155122 int nr_flags; /* 0 if nothing registered */ 180*f4b3ec61Sdh155122 void *(*nr_create)(netstackid_t, netstack_t *); 181*f4b3ec61Sdh155122 void (*nr_shutdown)(netstackid_t, void *); 182*f4b3ec61Sdh155122 void (*nr_destroy)(netstackid_t, void *); 183*f4b3ec61Sdh155122 }; 184*f4b3ec61Sdh155122 185*f4b3ec61Sdh155122 /* nr_flags values */ 186*f4b3ec61Sdh155122 #define NRF_REGISTERED 0x01 187*f4b3ec61Sdh155122 188*f4b3ec61Sdh155122 /* 189*f4b3ec61Sdh155122 * To support kstat_create_netstack() using kstat_add_zone we need 190*f4b3ec61Sdh155122 * to track both 191*f4b3ec61Sdh155122 * - all zoneids that use the global/shared stack 192*f4b3ec61Sdh155122 * - all kstats that have been added for the shared stack 193*f4b3ec61Sdh155122 */ 194*f4b3ec61Sdh155122 195*f4b3ec61Sdh155122 extern void netstack_init(void); 196*f4b3ec61Sdh155122 extern void netstack_hold(netstack_t *); 197*f4b3ec61Sdh155122 extern void netstack_rele(netstack_t *); 198*f4b3ec61Sdh155122 extern netstack_t *netstack_find_by_cred(const cred_t *); 199*f4b3ec61Sdh155122 extern netstack_t *netstack_find_by_stackid(netstackid_t); 200*f4b3ec61Sdh155122 extern netstack_t *netstack_find_by_zoneid(zoneid_t); 201*f4b3ec61Sdh155122 202*f4b3ec61Sdh155122 extern zoneid_t netstackid_to_zoneid(netstackid_t); 203*f4b3ec61Sdh155122 extern netstackid_t zoneid_to_netstackid(zoneid_t); 204*f4b3ec61Sdh155122 205*f4b3ec61Sdh155122 /* 206*f4b3ec61Sdh155122 * Register interest in changes to the set of netstacks. 207*f4b3ec61Sdh155122 * The createfn and destroyfn are required, but the shutdownfn can be 208*f4b3ec61Sdh155122 * NULL. 209*f4b3ec61Sdh155122 * Note that due to the current zsd implementation, when the create 210*f4b3ec61Sdh155122 * function is called the zone isn't fully present, thus functions 211*f4b3ec61Sdh155122 * like zone_find_by_* will fail, hence the create function can not 212*f4b3ec61Sdh155122 * use many zones kernel functions including zcmn_err(). 213*f4b3ec61Sdh155122 */ 214*f4b3ec61Sdh155122 extern void netstack_register(int, 215*f4b3ec61Sdh155122 void *(*)(netstackid_t, netstack_t *), 216*f4b3ec61Sdh155122 void (*)(netstackid_t, void *), 217*f4b3ec61Sdh155122 void (*)(netstackid_t, void *)); 218*f4b3ec61Sdh155122 extern void netstack_unregister(int); 219*f4b3ec61Sdh155122 extern kstat_t *kstat_create_netstack(char *, int, char *, char *, uchar_t, 220*f4b3ec61Sdh155122 uint_t, uchar_t, netstackid_t); 221*f4b3ec61Sdh155122 extern void kstat_delete_netstack(kstat_t *, netstackid_t); 222*f4b3ec61Sdh155122 223*f4b3ec61Sdh155122 /* 224*f4b3ec61Sdh155122 * Simple support for walking all the netstacks. 225*f4b3ec61Sdh155122 * The caller of netstack_next() needs to call netstack_rele() when 226*f4b3ec61Sdh155122 * done with a netstack. 227*f4b3ec61Sdh155122 */ 228*f4b3ec61Sdh155122 typedef int netstack_handle_t; 229*f4b3ec61Sdh155122 230*f4b3ec61Sdh155122 extern void netstack_next_init(netstack_handle_t *); 231*f4b3ec61Sdh155122 extern void netstack_next_fini(netstack_handle_t *); 232*f4b3ec61Sdh155122 extern netstack_t *netstack_next(netstack_handle_t *); 233*f4b3ec61Sdh155122 234*f4b3ec61Sdh155122 #ifdef __cplusplus 235*f4b3ec61Sdh155122 } 236*f4b3ec61Sdh155122 #endif 237*f4b3ec61Sdh155122 238*f4b3ec61Sdh155122 239*f4b3ec61Sdh155122 #endif /* _SYS_NETSTACK_H */ 240