xref: /onnv-gate/usr/src/uts/common/io/trill_impl.h (revision 10491:8893b747ecdf)
1*10491SRishi.Srivatsavai@Sun.COM /*
2*10491SRishi.Srivatsavai@Sun.COM  * CDDL HEADER START
3*10491SRishi.Srivatsavai@Sun.COM  *
4*10491SRishi.Srivatsavai@Sun.COM  * The contents of this file are subject to the terms of the
5*10491SRishi.Srivatsavai@Sun.COM  * Common Development and Distribution License (the "License").
6*10491SRishi.Srivatsavai@Sun.COM  * You may not use this file except in compliance with the License.
7*10491SRishi.Srivatsavai@Sun.COM  *
8*10491SRishi.Srivatsavai@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*10491SRishi.Srivatsavai@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*10491SRishi.Srivatsavai@Sun.COM  * See the License for the specific language governing permissions
11*10491SRishi.Srivatsavai@Sun.COM  * and limitations under the License.
12*10491SRishi.Srivatsavai@Sun.COM  *
13*10491SRishi.Srivatsavai@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*10491SRishi.Srivatsavai@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*10491SRishi.Srivatsavai@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*10491SRishi.Srivatsavai@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*10491SRishi.Srivatsavai@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*10491SRishi.Srivatsavai@Sun.COM  *
19*10491SRishi.Srivatsavai@Sun.COM  * CDDL HEADER END
20*10491SRishi.Srivatsavai@Sun.COM  */
21*10491SRishi.Srivatsavai@Sun.COM 
22*10491SRishi.Srivatsavai@Sun.COM /*
23*10491SRishi.Srivatsavai@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*10491SRishi.Srivatsavai@Sun.COM  * Use is subject to license terms.
25*10491SRishi.Srivatsavai@Sun.COM  */
26*10491SRishi.Srivatsavai@Sun.COM 
27*10491SRishi.Srivatsavai@Sun.COM #ifndef _TRILL_IMPL_H
28*10491SRishi.Srivatsavai@Sun.COM #define	_TRILL_IMPL_H
29*10491SRishi.Srivatsavai@Sun.COM 
30*10491SRishi.Srivatsavai@Sun.COM #ifdef __cplusplus
31*10491SRishi.Srivatsavai@Sun.COM extern "C" {
32*10491SRishi.Srivatsavai@Sun.COM #endif
33*10491SRishi.Srivatsavai@Sun.COM 
34*10491SRishi.Srivatsavai@Sun.COM #include <sys/list.h>
35*10491SRishi.Srivatsavai@Sun.COM #include <net/trill.h>
36*10491SRishi.Srivatsavai@Sun.COM #include <sys/mac.h>
37*10491SRishi.Srivatsavai@Sun.COM #include <sys/kstat.h>
38*10491SRishi.Srivatsavai@Sun.COM #include <sys/rwlock.h>
39*10491SRishi.Srivatsavai@Sun.COM #include <net/bridge_impl.h>
40*10491SRishi.Srivatsavai@Sun.COM #include <net/if_dl.h>
41*10491SRishi.Srivatsavai@Sun.COM 
42*10491SRishi.Srivatsavai@Sun.COM #define	TRILL_KSSOCK_NAMES "recv", "sent", "drops", "encap", "decap", "forward"
43*10491SRishi.Srivatsavai@Sun.COM 
44*10491SRishi.Srivatsavai@Sun.COM /* kstats per TRILL socket */
45*10491SRishi.Srivatsavai@Sun.COM typedef struct trill_kssock_s {
46*10491SRishi.Srivatsavai@Sun.COM 	kstat_named_t	tks_recv;	/* packets received */
47*10491SRishi.Srivatsavai@Sun.COM 	kstat_named_t	tks_sent;	/* packets sent through */
48*10491SRishi.Srivatsavai@Sun.COM 	kstat_named_t	tks_drops;	/* packets dropped */
49*10491SRishi.Srivatsavai@Sun.COM 	kstat_named_t   tks_encap;	/* packets encapsulated */
50*10491SRishi.Srivatsavai@Sun.COM 	kstat_named_t   tks_decap;	/* packets decapsulated */
51*10491SRishi.Srivatsavai@Sun.COM 	kstat_named_t	tks_forward;	/* packets forwarded */
52*10491SRishi.Srivatsavai@Sun.COM } trill_kssock_t;
53*10491SRishi.Srivatsavai@Sun.COM 
54*10491SRishi.Srivatsavai@Sun.COM #define	KSPINCR(stat) ++(tsock->ts_kstats.stat.value.ui64)
55*10491SRishi.Srivatsavai@Sun.COM 
56*10491SRishi.Srivatsavai@Sun.COM #define	TRILL_NO_TCI	0	/* No VLAN tag */
57*10491SRishi.Srivatsavai@Sun.COM #define	TRILL_VLANS_ARRSIZE ((1<<12)/NBBY)
58*10491SRishi.Srivatsavai@Sun.COM #define	TRILL_VLANBIT(v) ((v) % NBBY)
59*10491SRishi.Srivatsavai@Sun.COM #define	TRILL_VLANBYTE(v) ((v)/NBBY)
60*10491SRishi.Srivatsavai@Sun.COM #define	TRILL_VLANISSET(l, v) ((l)[TRILL_VLANBYTE(v)] & (1<<TRILL_VLANBIT(v)))
61*10491SRishi.Srivatsavai@Sun.COM 
62*10491SRishi.Srivatsavai@Sun.COM struct trill_node_s;
63*10491SRishi.Srivatsavai@Sun.COM 
64*10491SRishi.Srivatsavai@Sun.COM /*
65*10491SRishi.Srivatsavai@Sun.COM  * TRILL instance structure, one for each TRILL instance running in
66*10491SRishi.Srivatsavai@Sun.COM  * support of a bridge instance. Members ti_bridgename and ti_binst
67*10491SRishi.Srivatsavai@Sun.COM  * refer to the specific bridge instance. The bridge instance in
68*10491SRishi.Srivatsavai@Sun.COM  * question must be online before we can support and rely on it.
69*10491SRishi.Srivatsavai@Sun.COM  * We rely on the bridge instance for TRILL sockets to transmit and
70*10491SRishi.Srivatsavai@Sun.COM  * receive TRILL packets. Each TRILL instance holds the TRILL
71*10491SRishi.Srivatsavai@Sun.COM  * forwarding and nick database in ti_nodes. trill_inst_rwlock
72*10491SRishi.Srivatsavai@Sun.COM  * protects changes to the TRILL instances list. Within each TRILL
73*10491SRishi.Srivatsavai@Sun.COM  * instance the ti_rwlock protects changes to the structure. A refcount
74*10491SRishi.Srivatsavai@Sun.COM  * (ti_refs) helps in destroying the TRILL instance when all TRILL
75*10491SRishi.Srivatsavai@Sun.COM  * sockets part of the instance are shutdown.
76*10491SRishi.Srivatsavai@Sun.COM  */
77*10491SRishi.Srivatsavai@Sun.COM typedef struct trill_s {
78*10491SRishi.Srivatsavai@Sun.COM 	list_node_t		ti_instnode;
79*10491SRishi.Srivatsavai@Sun.COM 	uint16_t		ti_nick; /* our nickname */
80*10491SRishi.Srivatsavai@Sun.COM 	uint16_t		ti_treeroot; /* tree root nickname */
81*10491SRishi.Srivatsavai@Sun.COM 	struct trill_node_s	*ti_nodes[RBRIDGE_NICKNAME_MAX];
82*10491SRishi.Srivatsavai@Sun.COM 	uint_t			ti_nodecount;
83*10491SRishi.Srivatsavai@Sun.COM 	list_t			ti_socklist;
84*10491SRishi.Srivatsavai@Sun.COM 	char			ti_bridgename[MAXLINKNAMELEN];
85*10491SRishi.Srivatsavai@Sun.COM 	krwlock_t		ti_rwlock;
86*10491SRishi.Srivatsavai@Sun.COM 	uint_t			ti_refs;
87*10491SRishi.Srivatsavai@Sun.COM 	bridge_inst_t		*ti_binst;
88*10491SRishi.Srivatsavai@Sun.COM } trill_inst_t;
89*10491SRishi.Srivatsavai@Sun.COM 
90*10491SRishi.Srivatsavai@Sun.COM /*
91*10491SRishi.Srivatsavai@Sun.COM  * TRILL socket structure. IS-IS daemon opens a TRILL socket for
92*10491SRishi.Srivatsavai@Sun.COM  * each broadcast link the TRILL IS-IS protocol instance is
93*10491SRishi.Srivatsavai@Sun.COM  * running on. TRILL specific link properties, state and stats
94*10491SRishi.Srivatsavai@Sun.COM  * are stored as well. ts_vlanfwder indicates whether the RBridges
95*10491SRishi.Srivatsavai@Sun.COM  * is the designated forwarder on the link for a particular VLAN.
96*10491SRishi.Srivatsavai@Sun.COM  * A refcount (ts_refs) ensures the last consumer (TRILL module
97*10491SRishi.Srivatsavai@Sun.COM  * or the IS-IS daemon) destroys the socket.
98*10491SRishi.Srivatsavai@Sun.COM  */
99*10491SRishi.Srivatsavai@Sun.COM typedef struct trillsocket_s {
100*10491SRishi.Srivatsavai@Sun.COM 	list_node_t		ts_socklistnode;
101*10491SRishi.Srivatsavai@Sun.COM 	uint8_t			ts_state;
102*10491SRishi.Srivatsavai@Sun.COM 	bridge_link_t		*ts_link;
103*10491SRishi.Srivatsavai@Sun.COM 	struct sockaddr_dl	ts_lladdr;
104*10491SRishi.Srivatsavai@Sun.COM 	uint16_t		ts_desigvlan;
105*10491SRishi.Srivatsavai@Sun.COM 	kstat_t			*ts_ksp;
106*10491SRishi.Srivatsavai@Sun.COM 	trill_kssock_t		ts_kstats;
107*10491SRishi.Srivatsavai@Sun.COM 	trill_inst_t		*ts_tip;
108*10491SRishi.Srivatsavai@Sun.COM 	uint_t			ts_refs;
109*10491SRishi.Srivatsavai@Sun.COM 	uint_t			ts_flags;
110*10491SRishi.Srivatsavai@Sun.COM 	sock_upcalls_t		*ts_conn_upcalls;	/* Upcalls to sockfs */
111*10491SRishi.Srivatsavai@Sun.COM 	sock_upper_handle_t	ts_conn_upper_handle;	/* sonode */
112*10491SRishi.Srivatsavai@Sun.COM 	boolean_t		ts_flow_ctrld;
113*10491SRishi.Srivatsavai@Sun.COM 	kmutex_t		ts_socklock;
114*10491SRishi.Srivatsavai@Sun.COM 	uint_t			ts_sockthreadcount;
115*10491SRishi.Srivatsavai@Sun.COM 	kcondvar_t		ts_sockthreadwait;
116*10491SRishi.Srivatsavai@Sun.COM 	kcondvar_t		ts_sockclosewait;
117*10491SRishi.Srivatsavai@Sun.COM } trill_sock_t;
118*10491SRishi.Srivatsavai@Sun.COM 
119*10491SRishi.Srivatsavai@Sun.COM /*
120*10491SRishi.Srivatsavai@Sun.COM  * TRILL socket flags (ts_flags). TSF_SHUTDOWN indicates the TRILL socket
121*10491SRishi.Srivatsavai@Sun.COM  * owner (IS-IS daemon process) had done a close on the socket and other
122*10491SRishi.Srivatsavai@Sun.COM  * consumers (TRILL threads) should not pass any packets downstream.
123*10491SRishi.Srivatsavai@Sun.COM  * TSF_CLOSEWAIT indicates socket close is in progress.
124*10491SRishi.Srivatsavai@Sun.COM  */
125*10491SRishi.Srivatsavai@Sun.COM #define	TSF_SHUTDOWN	0x0001
126*10491SRishi.Srivatsavai@Sun.COM #define	TSF_CLOSEWAIT	0x0002
127*10491SRishi.Srivatsavai@Sun.COM 
128*10491SRishi.Srivatsavai@Sun.COM /*
129*10491SRishi.Srivatsavai@Sun.COM  * TRILL node information structure. Holds information to reach the
130*10491SRishi.Srivatsavai@Sun.COM  * TRILL node and other RBridge information specified in trill_nick_info_t
131*10491SRishi.Srivatsavai@Sun.COM  */
132*10491SRishi.Srivatsavai@Sun.COM typedef struct trill_node_s {
133*10491SRishi.Srivatsavai@Sun.COM 	trill_sock_t		*tn_tsp;
134*10491SRishi.Srivatsavai@Sun.COM 	trill_nickinfo_t	*tn_ni;
135*10491SRishi.Srivatsavai@Sun.COM 	uint_t			tn_refs;
136*10491SRishi.Srivatsavai@Sun.COM } trill_node_t;
137*10491SRishi.Srivatsavai@Sun.COM 
138*10491SRishi.Srivatsavai@Sun.COM /* Limit to alloc max 1MB per trill_nickinfo_t received from user daemon */
139*10491SRishi.Srivatsavai@Sun.COM #define	TNI_MAXSIZE	(1<<30)
140*10491SRishi.Srivatsavai@Sun.COM 
141*10491SRishi.Srivatsavai@Sun.COM #ifdef __cplusplus
142*10491SRishi.Srivatsavai@Sun.COM }
143*10491SRishi.Srivatsavai@Sun.COM #endif
144*10491SRishi.Srivatsavai@Sun.COM 
145*10491SRishi.Srivatsavai@Sun.COM #endif /* _TRILL_IMPL_H */
146