ipnet.h revision 0a0e9771ca0211c15f3ac4466b661c145feeb9e4
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _INET_IPNET_H
#define _INET_IPNET_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/netstack.h>
#include <sys/hook_event.h>
typedef struct ipnet_kstats_s {
/*
* Structure used to hold information for both IPv4 and IPv6 addresses.
*
* When ifa_shared is non-NULL, it points to a "fake" ipnetif_t structure
* that represents the network interface for each zone that shares its
* network stack. This is used by BPF to build a list of interface names
* present in each zone. Multiple ipnetif_addr_t's may point to a single
* ipnetif_t using ifa_shared. The typical case is the global zone has
* a bge0 that other zones use as bge0:1, bge0:2, etc. In ipnet, the
* ipnetif_addr_t's that store the IP address for bge0:1, etc, would
* point to an ipnetif_t stored in the if_avl_by_shared tree that has
* the name "bge0".
*/
typedef struct ipnetif_addr {
union {
} ifa_addr;
struct ipnetif *ifa_shared;
/*
* Structure describes the ipnet module representation of an ip interface.
* The structure holds both IPv4 and IPv6 addresses, the address lists are
* protected by a mutex. The ipnetif structures are held per stack instance
* within avl trees indexed on name and ip index.
*
* if_avl_by_shared is used by zones that share their instance of IP with
* other zones. It is used to store ipnetif_t structures. An example of this
* is the global zone sharing its instance of IP with other local zones.
* In this case, if_avl_by_shared is a tree of names that are in active use
* by zones using a shared instance of IP.
* The value in if_sharecnt represents the number of ipnetif_addr_t's that
* point to it.
*/
typedef struct ipnetif {
int if_refcnt; /* if_reflock */
struct ipnet_stack *if_stackp;
int if_sharecnt; /* protected by if_reflock */
} ipnetif_t;
/* if_flags */
#define IPNETIF_IPV4PLUMBED 0x01
#define IPNETIF_IPV6PLUMBED 0x02
#define IPNETIF_IPV4ALLMULTI 0x04
#define IPNETIF_IPV6ALLMULTI 0x08
#define IPNETIF_LOOPBACK 0x10
/*
* Structure used by the accept callback function. This is simply an address
* pointer into a packet (either IPv4 or IPv6), along with an address family
* that denotes which pointer is valid.
*/
typedef struct ipnet_addrp {
union {
} iap_addrp;
struct ipnet;
struct ipobs_hook_data;
ipnet_addrp_t *, ipnet_addrp_t *);
/*
* Per instance data for all open streams. Instance data is held on a
* per netstack list see struct ipnet_stack below.
*/
typedef struct ipnet {
void *ipnet_data; /* value to pass back to bpf_itap */
} ipnet_t;
/* ipnet_flags */
#define IPNET_PROMISC_PHYS 0x01
#define IPNET_PROMISC_MULTI 0x02
#define IPNET_PROMISC_SAP 0x04
#define IPNET_INFO 0x08
#define IPNET_LOMODE 0x10
/*
* Per-netstack data holding:
* - net_handle_t references for IPv4 and IPv6 for this netstack.
* - avl trees by name and index for ip interfaces associated with this
* netstack. The trees are protected by ips_avl_lock.
* - ips_str_list is a list of open client streams. ips_walkers_lock in
* conjunction with ips_walkers_cv and ips_walkers_cnt synchronize access to
* the list. The count is incremented in ipnet_dispatch() at the start of a
* walk and decremented when the walk is finished. If the walkers count is 0
* then we cv_broadcast() waiting any threads waiting on the walkers count.
* - ips_event_lock synchronizes ipnet_if_init() and incoming NIC info events.
* We cannot be processing any NIC info events while initializing interfaces
* in ipnet_if_init().
*
* Note on lock ordering: If a thread needs to both hold the ips_event_lock
* and any other lock such as ips_walkers_lock, ips_avl_lock, or if_addr_lock,
* the ips_event_lock must be held first. This lock ordering is mandated by
* ipnet_nicevent_cb() which must always grab ips_event_lock before continuing
* with processing NIC events.
*/
typedef struct ipnet_stack {
/*
* Template for dl_info_ack_t initialization. We don't have an address, so we
* set the address length to just the SAP length (16 bits). We don't really
* have a maximum SDU, but setting it to UINT_MAX proved problematic with
* applications that performed arithmetic on dl_max_sdu and wrapped around, so
* we sleaze out and use INT_MAX.
*/
#define IPNET_INFO_ACK_INIT { \
DL_INFO_ACK, /* dl_primitive */ \
INT_MAX, /* dl_max_sdu */ \
0, /* dl_min_sdu */ \
sizeof (uint16_t), /* dl_addr_length */ \
DL_IPNET, /* dl_mac_type */ \
0, /* dl_reserved */ \
0, /* dl_current_state */ \
sizeof (uint16_t), /* dl_sap_length */ \
DL_CLDLS, /* dl_service_mode */ \
0, /* dl_qos_length */ \
0, /* dl_qos_offset */ \
0, /* dl_range_length */ \
0, /* dl_range_offset */ \
DL_STYLE1, /* dl_provider_style */ \
0, /* dl_addr_offset */ \
DL_VERSION_2, /* dl_version */ \
0, /* dl_brdcst_addr_length */ \
0 /* dl_brdcst_addr_offset */ \
}
typedef void ipnet_walkfunc_t(const char *, void *, dev_t);
extern void ipnet_client_close(ipnetif_t *);
extern void ipnet_close_byhandle(ipnetif_t *);
extern int ipnet_get_linkid_byname(const char *, datalink_id_t *,
zoneid_t);
extern const char *ipnet_name(ipnetif_t *);
extern void ipnet_promisc_remove(void *);
extern bpf_provider_t bpf_ipnet;
#ifdef __cplusplus
}
#endif
#endif /* _INET_IPNET_H */