13448Sdh155122 /* 23448Sdh155122 * CDDL HEADER START 33448Sdh155122 * 43448Sdh155122 * The contents of this file are subject to the terms of the 53448Sdh155122 * Common Development and Distribution License (the "License"). 63448Sdh155122 * You may not use this file except in compliance with the License. 73448Sdh155122 * 83448Sdh155122 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93448Sdh155122 * or http://www.opensolaris.org/os/licensing. 103448Sdh155122 * See the License for the specific language governing permissions 113448Sdh155122 * and limitations under the License. 123448Sdh155122 * 133448Sdh155122 * When distributing Covered Code, include this CDDL HEADER in each 143448Sdh155122 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153448Sdh155122 * If applicable, add the following below this CDDL HEADER, with the 163448Sdh155122 * fields enclosed by brackets "[]" replaced with your own identifying 173448Sdh155122 * information: Portions Copyright [yyyy] [name of copyright owner] 183448Sdh155122 * 193448Sdh155122 * CDDL HEADER END 203448Sdh155122 */ 213448Sdh155122 223448Sdh155122 /* 233448Sdh155122 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 243448Sdh155122 * Use is subject to license terms. 253448Sdh155122 */ 263448Sdh155122 #ifndef _SYS_NETSTACK_H 273448Sdh155122 #define _SYS_NETSTACK_H 283448Sdh155122 293448Sdh155122 #pragma ident "%Z%%M% %I% %E% SMI" 303448Sdh155122 313448Sdh155122 #include <sys/kstat.h> 323448Sdh155122 333448Sdh155122 #ifdef __cplusplus 343448Sdh155122 extern "C" { 353448Sdh155122 #endif 363448Sdh155122 373448Sdh155122 /* 383448Sdh155122 * This allows various pieces in and around IP to have a separate instance 393448Sdh155122 * for each instance of IP. This is used to support zones that have an 403448Sdh155122 * exclusive stack. 413448Sdh155122 * Pieces of software far removed from IP (e.g., kernel software 423448Sdh155122 * sitting on top of TCP or UDP) probably should not use the netstack 433448Sdh155122 * support; if such software wants to support separate zones it 443448Sdh155122 * can do that using the zones framework (zone_key_create() etc) 453448Sdh155122 * whether there is a shared IP stack or and exclusive IP stack underneath. 463448Sdh155122 */ 473448Sdh155122 483448Sdh155122 /* 493448Sdh155122 * Each netstack has an identifier. We reuse the zoneid allocation for 503448Sdh155122 * this but have a separate typedef. Thus the shared stack (used by 513448Sdh155122 * the global zone and other shared stack zones) have a zero ID, and 523448Sdh155122 * the exclusive stacks have a netstackid that is the same as their zoneid. 533448Sdh155122 */ 543448Sdh155122 typedef id_t netstackid_t; 553448Sdh155122 563448Sdh155122 #define GLOBAL_NETSTACKID 0 573448Sdh155122 583448Sdh155122 /* 593448Sdh155122 * One for each module which uses netstack support. 603448Sdh155122 * Used in netstack_register(). 613448Sdh155122 * 623448Sdh155122 * The order of these is important for some modules both for 633448Sdh155122 * the creation (which done in ascending order) and destruction (which is 643448Sdh155122 * done ine in decending order). 653448Sdh155122 */ 663448Sdh155122 #define NS_HOOK 0 673448Sdh155122 #define NS_NETI 1 683448Sdh155122 #define NS_ARP 2 693448Sdh155122 #define NS_IP 3 703448Sdh155122 #define NS_ICMP 4 713448Sdh155122 #define NS_UDP 5 723448Sdh155122 #define NS_TCP 6 733448Sdh155122 #define NS_SCTP 7 743448Sdh155122 #define NS_RTS 8 753448Sdh155122 #define NS_IPSEC 9 763448Sdh155122 #define NS_KEYSOCK 10 773448Sdh155122 #define NS_SPDSOCK 11 783448Sdh155122 #define NS_IPSECAH 12 793448Sdh155122 #define NS_IPSECESP 13 803448Sdh155122 #define NS_TUN 14 813448Sdh155122 #define NS_IPF 15 823448Sdh155122 #define NS_STR 16 /* autopush list etc */ 833448Sdh155122 #define NS_MAX (NS_STR+1) 843448Sdh155122 853448Sdh155122 /* 863448Sdh155122 * One for every netstack in the system. 873448Sdh155122 * We use a union so that the compilar and lint can provide type checking - 883448Sdh155122 * in principle we could have 893448Sdh155122 * #define netstack_arp netstack_modules[NS_ARP] 903448Sdh155122 * etc, but that would imply void * types hence no type checking by the 913448Sdh155122 * compiler. 923448Sdh155122 * 933448Sdh155122 * All the fields in netstack_t except netstack_next are protected by 943448Sdh155122 * netstack_lock. netstack_next is protected by netstack_g_lock. 953448Sdh155122 */ 963448Sdh155122 struct netstack { 973448Sdh155122 union { 983448Sdh155122 void *nu_modules[NS_MAX]; 993448Sdh155122 struct { 1003448Sdh155122 struct hook_stack *nu_hook; 1013448Sdh155122 struct neti_stack *nu_neti; 1023448Sdh155122 struct arp_stack *nu_arp; 1033448Sdh155122 struct ip_stack *nu_ip; 1043448Sdh155122 struct icmp_stack *nu_icmp; 1053448Sdh155122 struct udp_stack *nu_udp; 1063448Sdh155122 struct tcp_stack *nu_tcp; 1073448Sdh155122 struct sctp_stack *nu_sctp; 1083448Sdh155122 struct rts_stack *nu_rts; 1093448Sdh155122 struct ipsec_stack *nu_ipsec; 1103448Sdh155122 struct keysock_stack *nu_keysock; 1113448Sdh155122 struct spd_stack *nu_spdsock; 1123448Sdh155122 struct ipsecah_stack *nu_ipsecah; 1133448Sdh155122 struct ipsecesp_stack *nu_ipsecesp; 1143448Sdh155122 struct tun_stack *nu_tun; 1153448Sdh155122 struct ipf_stack *nu_ipf; 1163448Sdh155122 struct str_stack *nu_str; 1173448Sdh155122 } nu_s; 1183448Sdh155122 } netstack_u; 1193448Sdh155122 #define netstack_modules netstack_u.nu_modules 1203448Sdh155122 #define netstack_hook netstack_u.nu_s.nu_hook 1213448Sdh155122 #define netstack_neti netstack_u.nu_s.nu_neti 1223448Sdh155122 #define netstack_arp netstack_u.nu_s.nu_arp 1233448Sdh155122 #define netstack_ip netstack_u.nu_s.nu_ip 1243448Sdh155122 #define netstack_icmp netstack_u.nu_s.nu_icmp 1253448Sdh155122 #define netstack_udp netstack_u.nu_s.nu_udp 1263448Sdh155122 #define netstack_tcp netstack_u.nu_s.nu_tcp 1273448Sdh155122 #define netstack_sctp netstack_u.nu_s.nu_sctp 1283448Sdh155122 #define netstack_rts netstack_u.nu_s.nu_rts 1293448Sdh155122 #define netstack_ipsec netstack_u.nu_s.nu_ipsec 1303448Sdh155122 #define netstack_keysock netstack_u.nu_s.nu_keysock 1313448Sdh155122 #define netstack_spdsock netstack_u.nu_s.nu_spdsock 1323448Sdh155122 #define netstack_ipsecah netstack_u.nu_s.nu_ipsecah 1333448Sdh155122 #define netstack_ipsecesp netstack_u.nu_s.nu_ipsecesp 1343448Sdh155122 #define netstack_tun netstack_u.nu_s.nu_tun 1353448Sdh155122 #define netstack_ipf netstack_u.nu_s.nu_ipf 1363448Sdh155122 #define netstack_str netstack_u.nu_s.nu_str 1373448Sdh155122 1383448Sdh155122 uint16_t netstack_m_state[NS_MAX]; /* module state */ 1393448Sdh155122 1403448Sdh155122 kmutex_t netstack_lock; 1413448Sdh155122 struct netstack *netstack_next; 1423448Sdh155122 netstackid_t netstack_stackid; 1433448Sdh155122 int netstack_numzones; /* Number of zones using this */ 1443448Sdh155122 int netstack_refcnt; /* Number of hold-rele */ 1453448Sdh155122 int netstack_flags; /* See below */ 1463448Sdh155122 }; 1473448Sdh155122 typedef struct netstack netstack_t; 1483448Sdh155122 1493448Sdh155122 /* netstack_flags values */ 1503448Sdh155122 #define NSF_UNINIT 0x01 /* Not initialized */ 1513448Sdh155122 #define NSF_CLOSING 0x02 /* Going away */ 1523448Sdh155122 1533448Sdh155122 /* 1543448Sdh155122 * State for each module for each stack - netstack_m_state[moduleid] 1553448Sdh155122 * Keeps track of pending actions to avoid holding looks when 1563448Sdh155122 * calling into the create/shutdown/destroy functions in the module. 1573448Sdh155122 */ 1583448Sdh155122 #define NSS_CREATE_NEEDED 0x0001 1593448Sdh155122 #define NSS_CREATE_INPROGRESS 0x0002 1603448Sdh155122 #define NSS_CREATE_COMPLETED 0x0004 1613448Sdh155122 #define NSS_SHUTDOWN_NEEDED 0x0010 1623448Sdh155122 #define NSS_SHUTDOWN_INPROGRESS 0x0020 1633448Sdh155122 #define NSS_SHUTDOWN_COMPLETED 0x0040 1643448Sdh155122 #define NSS_DESTROY_NEEDED 0x0100 1653448Sdh155122 #define NSS_DESTROY_INPROGRESS 0x0200 1663448Sdh155122 #define NSS_DESTROY_COMPLETED 0x0400 1673448Sdh155122 1683448Sdh155122 #define NSS_CREATE_ALL \ 1693448Sdh155122 (NSS_CREATE_NEEDED|NSS_CREATE_INPROGRESS|NSS_CREATE_COMPLETED) 1703448Sdh155122 #define NSS_SHUTDOWN_ALL \ 1713448Sdh155122 (NSS_SHUTDOWN_NEEDED|NSS_SHUTDOWN_INPROGRESS|NSS_SHUTDOWN_COMPLETED) 1723448Sdh155122 #define NSS_DESTROY_ALL \ 1733448Sdh155122 (NSS_DESTROY_NEEDED|NSS_DESTROY_INPROGRESS|NSS_DESTROY_COMPLETED) 1743448Sdh155122 1753448Sdh155122 /* 1763448Sdh155122 * One for each of the NS_* values. 1773448Sdh155122 */ 1783448Sdh155122 struct netstack_registry { 1793448Sdh155122 int nr_flags; /* 0 if nothing registered */ 1803448Sdh155122 void *(*nr_create)(netstackid_t, netstack_t *); 1813448Sdh155122 void (*nr_shutdown)(netstackid_t, void *); 1823448Sdh155122 void (*nr_destroy)(netstackid_t, void *); 1833448Sdh155122 }; 1843448Sdh155122 1853448Sdh155122 /* nr_flags values */ 1863448Sdh155122 #define NRF_REGISTERED 0x01 1873448Sdh155122 1883448Sdh155122 /* 1893448Sdh155122 * To support kstat_create_netstack() using kstat_add_zone we need 1903448Sdh155122 * to track both 1913448Sdh155122 * - all zoneids that use the global/shared stack 1923448Sdh155122 * - all kstats that have been added for the shared stack 1933448Sdh155122 */ 1943448Sdh155122 1953448Sdh155122 extern void netstack_init(void); 1963448Sdh155122 extern void netstack_hold(netstack_t *); 1973448Sdh155122 extern void netstack_rele(netstack_t *); 1983448Sdh155122 extern netstack_t *netstack_find_by_cred(const cred_t *); 1993448Sdh155122 extern netstack_t *netstack_find_by_stackid(netstackid_t); 2003448Sdh155122 extern netstack_t *netstack_find_by_zoneid(zoneid_t); 2013448Sdh155122 2023448Sdh155122 extern zoneid_t netstackid_to_zoneid(netstackid_t); 2033448Sdh155122 extern netstackid_t zoneid_to_netstackid(zoneid_t); 2043448Sdh155122 205*4136Snordmark extern netstack_t *netstack_get_current(void); 206*4136Snordmark 2073448Sdh155122 /* 2083448Sdh155122 * Register interest in changes to the set of netstacks. 2093448Sdh155122 * The createfn and destroyfn are required, but the shutdownfn can be 2103448Sdh155122 * NULL. 2113448Sdh155122 * Note that due to the current zsd implementation, when the create 2123448Sdh155122 * function is called the zone isn't fully present, thus functions 2133448Sdh155122 * like zone_find_by_* will fail, hence the create function can not 2143448Sdh155122 * use many zones kernel functions including zcmn_err(). 2153448Sdh155122 */ 2163448Sdh155122 extern void netstack_register(int, 2173448Sdh155122 void *(*)(netstackid_t, netstack_t *), 2183448Sdh155122 void (*)(netstackid_t, void *), 2193448Sdh155122 void (*)(netstackid_t, void *)); 2203448Sdh155122 extern void netstack_unregister(int); 2213448Sdh155122 extern kstat_t *kstat_create_netstack(char *, int, char *, char *, uchar_t, 2223448Sdh155122 uint_t, uchar_t, netstackid_t); 2233448Sdh155122 extern void kstat_delete_netstack(kstat_t *, netstackid_t); 2243448Sdh155122 2253448Sdh155122 /* 2263448Sdh155122 * Simple support for walking all the netstacks. 2273448Sdh155122 * The caller of netstack_next() needs to call netstack_rele() when 2283448Sdh155122 * done with a netstack. 2293448Sdh155122 */ 2303448Sdh155122 typedef int netstack_handle_t; 2313448Sdh155122 2323448Sdh155122 extern void netstack_next_init(netstack_handle_t *); 2333448Sdh155122 extern void netstack_next_fini(netstack_handle_t *); 2343448Sdh155122 extern netstack_t *netstack_next(netstack_handle_t *); 2353448Sdh155122 2363448Sdh155122 #ifdef __cplusplus 2373448Sdh155122 } 2383448Sdh155122 #endif 2393448Sdh155122 2403448Sdh155122 2413448Sdh155122 #endif /* _SYS_NETSTACK_H */ 242