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