netstack.h revision 7ddc9b1afd18f260b9fb78ec7732facd91769131
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * CDDL HEADER START
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * The contents of this file are subject to the terms of the
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Common Development and Distribution License (the "License").
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * You may not use this file except in compliance with the License.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * See the License for the specific language governing permissions
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * and limitations under the License.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * When distributing Covered Code, include this CDDL HEADER in each
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * If applicable, add the following below this CDDL HEADER, with the
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * fields enclosed by brackets "[]" replaced with your own identifying
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * information: Portions Copyright [yyyy] [name of copyright owner]
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * CDDL HEADER END
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Use is subject to license terms.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhextern "C" {
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * This allows various pieces in and around IP to have a separate instance
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * for each instance of IP. This is used to support zones that have an
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * exclusive stack.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Pieces of software far removed from IP (e.g., kernel software
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * sitting on top of TCP or UDP) probably should not use the netstack
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * support; if such software wants to support separate zones it
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * can do that using the zones framework (zone_key_create() etc)
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * whether there is a shared IP stack or and exclusive IP stack underneath.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Each netstack has an identifier. We reuse the zoneid allocation for
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * this but have a separate typedef. Thus the shared stack (used by
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * the global zone and other shared stack zones) have a zero ID, and
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * the exclusive stacks have a netstackid that is the same as their zoneid.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * One for each module which uses netstack support.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Used in netstack_register().
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * The order of these is important for some modules both for
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * the creation (which done in ascending order) and destruction (which is
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * done ine in decending order).
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark * State maintained for each module which tracks the state of
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark * the create, shutdown and destroy callbacks.
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark * Keeps track of pending actions to avoid holding locks when
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark * calling into the create/shutdown/destroy functions in the module.
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmarktypedef struct {
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark * nms_flags
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark (NSS_CREATE_NEEDED|NSS_CREATE_INPROGRESS|NSS_CREATE_COMPLETED)
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark (NSS_SHUTDOWN_NEEDED|NSS_SHUTDOWN_INPROGRESS|NSS_SHUTDOWN_COMPLETED)
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark (NSS_DESTROY_NEEDED|NSS_DESTROY_INPROGRESS|NSS_DESTROY_COMPLETED)
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark (NSS_CREATE_INPROGRESS|NSS_SHUTDOWN_INPROGRESS|NSS_DESTROY_INPROGRESS)
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark/* User-level compile like IP Filter needs a netstack_t. Dummy */
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark#endif /* _KERNEL */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * One for every netstack in the system.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * We use a union so that the compilar and lint can provide type checking -
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * in principle we could have
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * #define netstack_arp netstack_modules[NS_ARP]
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * etc, but that would imply void * types hence no type checking by the
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * compiler.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * All the fields in netstack_t except netstack_next are protected by
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * netstack_lock. netstack_next is protected by netstack_g_lock.
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark nm_state_t netstack_m_state[NS_MAX]; /* module state */
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark /* Needed to ensure that we run the callback functions in order */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh/* netstack_flags values */
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark#define NSF_ZONE_CREATE 0x04 /* create callbacks inprog */
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark#define NSF_ZONE_SHUTDOWN 0x08 /* shutdown callbacks */
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark#define NSF_ZONE_DESTROY 0x10 /* destroy callbacks */
bd41d0a82bd89bc81d63ae5dfc2ba4245f74ea6cnordmark (NSF_ZONE_CREATE|NSF_ZONE_SHUTDOWN|NSF_ZONE_DESTROY)
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * One for each of the NS_* values.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh/* nr_flags values */
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * To support kstat_create_netstack() using kstat_add_zone we need
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * to track both
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * - all zoneids that use the global/shared stack
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * - all kstats that have been added for the shared stack
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhextern void netstack_init(void);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhextern netstack_t *netstack_find_by_stackid(netstackid_t);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Register interest in changes to the set of netstacks.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * The createfn and destroyfn are required, but the shutdownfn can be
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Note that due to the current zsd implementation, when the create
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * function is called the zone isn't fully present, thus functions
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * like zone_find_by_* will fail, hence the create function can not
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * use many zones kernel functions including zcmn_err().
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhextern void netstack_register(int,
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh void (*)(netstackid_t, void *),
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh void (*)(netstackid_t, void *));
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhextern void netstack_unregister(int);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhextern kstat_t *kstat_create_netstack(char *, int, char *, char *, uchar_t,
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dhextern void kstat_delete_netstack(kstat_t *, netstackid_t);
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * Simple support for walking all the netstacks.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * The caller of netstack_next() needs to call netstack_rele() when
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh * done with a netstack.
f4b3ec61df05330d25f55a36b975b4d7519fdeb1dh#endif /* _SYS_NETSTACK_H */