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