1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2018 Joyent, Inc.
14 */
15
16 #ifndef _SYS_OVERLAY_IMPL_H
17 #define _SYS_OVERLAY_IMPL_H
18
19 /*
20 * Overlay device support
21 */
22
23 #include <sys/overlay.h>
24 #include <sys/overlay_common.h>
25 #include <sys/overlay_plugin.h>
26 #include <sys/overlay_target.h>
27 #include <sys/ksynch.h>
28 #include <sys/list.h>
29 #include <sys/avl.h>
30 #include <sys/ksocket.h>
31 #include <sys/socket.h>
32 #include <sys/refhash.h>
33 #include <sys/ethernet.h>
34 #include <sys/list.h>
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 #define OVEP_VERSION_ONE 0x1
41
42 typedef struct overlay_plugin {
43 kmutex_t ovp_mutex;
44 list_node_t ovp_link; /* overlay_plugin_lock */
45 uint_t ovp_active; /* ovp_mutex */
46 const char *ovp_name; /* RO */
47 const overlay_plugin_ops_t *ovp_ops; /* RO */
48 const char *const *ovp_props; /* RO */
49 uint_t ovp_nprops; /* RO */
50 uint_t ovp_id_size; /* RO */
51 overlay_plugin_flags_t ovp_flags; /* RO */
52 overlay_plugin_dest_t ovp_dest; /* RO */
53 } overlay_plugin_t;
54
55 typedef struct overlay_mux {
56 list_node_t omux_lnode;
57 ksocket_t omux_ksock; /* RO */
58 overlay_plugin_t *omux_plugin; /* RO: associated encap */
59 int omux_domain; /* RO: socket domain */
60 int omux_family; /* RO: socket family */
61 int omux_protocol; /* RO: socket protocol */
62 struct sockaddr *omux_addr; /* RO: socket address */
63 socklen_t omux_alen; /* RO: sockaddr len */
64 kmutex_t omux_lock; /* Protects everything below */
65 uint_t omux_count; /* Active instances */
66 avl_tree_t omux_devices; /* Tree of devices */
67 } overlay_mux_t;
68
69 typedef enum overlay_target_flag {
70 OVERLAY_T_TEARDOWN = 0x1
71 } overlay_target_flag_t;
72
73 typedef struct overlay_target {
74 kmutex_t ott_lock;
75 kcondvar_t ott_cond;
76 overlay_target_mode_t ott_mode; /* RO */
77 overlay_plugin_dest_t ott_dest; /* RO */
78 uint64_t ott_id; /* RO */
79 overlay_target_flag_t ott_flags; /* ott_lock */
80 uint_t ott_ocount; /* ott_lock */
81 union { /* ott_lock */
82 overlay_target_point_t ott_point;
83 struct overlay_target_dyn {
84 refhash_t *ott_dhash;
85 refhash_t *ott_l3dhash;
86 avl_tree_t ott_tree;
87 /* XXX: Do we actually need a tree sorted by VL3? */
88 avl_tree_t ott_l3tree;
89 } ott_dyn;
90 } ott_u;
91 } overlay_target_t;
92
93 /*
94 * Initially at least, we represent a group of fabrics that are attached to
95 * each other as a circular linked list. Within an overlay_dev_t, we then
96 * maintain a list of pointers into these lists for each fabric that's
97 * present locally on the CN as we learn them:
98 *
99 */
100 typedef struct overlay_fabric_attach {
101 struct overlay_fabric_attach *ofa_next;
102 struct in6_addr ofa_addr;
103 uint32_t ofa_dcid;
104 uint16_t ofa_vlan;
105 uint8_t ofa_prefixlen;
106 uint8_t ofa_pad;
107 } overlay_fabric_attach_t;
108
109 /*
110 * Since we have two different refhashes for an overlay_target_entry_t
111 * (VL2 aka MAC address and VL3 aka IP address), we want to maintain
112 * the refcount in only one place. We elect to use the ott_dhash
113 * refhash to do so.
114 */
115 #define OVERLAY_TARGET_ENTRY_HOLD(tgt, e) \
116 refhash_hold((tgt)->ott_u.ott_dyn.ott_dhash, e)
117 #define OVERLAY_TARGET_ENTRY_RELE(tgt, e) \
118 refhash_rele((tgt)->ott_u.ott_dyn.ott_dhash, e)
119
120 typedef enum overlay_dev_flag {
121 OVERLAY_F_ACTIVATED = 0x01, /* Activate ioctl completed */
122 OVERLAY_F_IN_MUX = 0x02, /* Currently in a mux */
123 OVERLAY_F_IN_TX = 0x04, /* Currently doing tx */
124 OVERLAY_F_IN_RX = 0x08, /* Currently doing rx */
125 OVERLAY_F_IOMASK = 0x0c, /* A mask for rx and tx */
126 OVERLAY_F_MDDROP = 0x10, /* Drop traffic for metadata update */
127 OVERLAY_F_STOPMASK = 0x1e, /* None set when stopping */
128 OVERLAY_F_VARPD = 0x20, /* varpd plugin exists */
129 OVERLAY_F_DEGRADED = 0x40, /* device is degraded */
130 OVERLAY_F_MASK = 0x7f /* mask of everything */
131 } overlay_dev_flag_t;
132
133 typedef struct overlay_dev {
134 kmutex_t odd_lock;
135 kcondvar_t odd_iowait;
136 list_node_t odd_link; /* overlay_dev_lock */
137 mac_handle_t odd_mh; /* RO */
138 overlay_plugin_t *odd_plugin; /* RO */
139 datalink_id_t odd_linkid; /* RO */
140 void *odd_pvoid; /* RO -- only used by plugin */
141 uint_t odd_ref; /* protected by odd_lock */
142 uint_t odd_mtu; /* protected by odd_lock */
143 overlay_dev_flag_t odd_flags; /* protected by odd_lock */
144 uint_t odd_rxcount; /* protected by odd_lock */
145 uint_t odd_txcount; /* protected by odd_lock */
146 overlay_mux_t *odd_mux; /* protected by odd_lock */
147 uint64_t odd_vid; /* RO if active else odd_lock */
148 avl_node_t odd_muxnode; /* managed by mux */
149 overlay_target_t *odd_target; /* See big theory statement */
150 overlay_fabric_attach_t **odd_fattach; /* protected by odd_lock */
151 uint32_t odd_dcid; /* RO if active else odd_lock */
152 uint8_t odd_macaddr[ETHERADDRL]; /* RO same as odd_dcid */
153 char odd_fmamsg[OVERLAY_STATUS_BUFLEN]; /* odd_lock */
154 } overlay_dev_t;
155
156 typedef enum overlay_target_entry_flags {
157 OVERLAY_ENTRY_F_PENDING = 0x01, /* lookup in progress */
158 OVERLAY_ENTRY_F_VALID = 0x02, /* entry is currently valid */
159 OVERLAY_ENTRY_F_DROP = 0x04, /* always drop target */
160 OVERLAY_ENTRY_F_VALID_MASK = 0x06
161 } overlay_target_entry_flags_t;
162
163 typedef struct overlay_target_entry {
164 kmutex_t ote_lock;
165 refhash_link_t ote_reflink; /* hashtable link */
166 refhash_link_t ote_l3_reflink; /* IP hashtable link */
167 avl_node_t ote_avllink; /* iteration link */
168 avl_node_t ote_l3_avllink; /* IP iteration link */
169 list_node_t ote_qlink;
170 overlay_target_entry_flags_t ote_flags; /* RW: state flags */
171 uint32_t ote_dcid;
172 uint16_t ote_vlan; /* RO: VL3 vlan id */
173 uint8_t ote_addr[ETHERADDRL]; /* RO: mac addr */
174 struct in6_addr ote_ip; /* RO: VL3 IP */
175 overlay_target_t *ote_ott; /* RO */
176 overlay_dev_t *ote_odd; /* RO */
177 overlay_target_point_t ote_dest; /* RW: destination */
178 mblk_t *ote_chead; /* RW: blocked mb chain head */
179 mblk_t *ote_ctail; /* RW: blocked mb chain tail */
180 size_t ote_mbsize; /* RW: outstanding mblk size */
181 hrtime_t ote_vtime; /* RW: valid timestamp */
182 } overlay_target_entry_t;
183
184 #define OVERLAY_CTL "overlay"
185
186 extern dev_info_t *overlay_dip;
187
188 extern mblk_t *overlay_m_tx(void *, mblk_t *);
189
190 typedef int (*overlay_dev_iter_f)(overlay_dev_t *, void *);
191 extern void overlay_dev_iter(overlay_dev_iter_f, void *);
192
193 extern void overlay_plugin_init(void);
194 extern overlay_plugin_t *overlay_plugin_lookup(const char *);
195 extern void overlay_plugin_rele(overlay_plugin_t *);
196 extern void overlay_plugin_fini(void);
197 typedef int (*overlay_plugin_walk_f)(overlay_plugin_t *, void *);
198 extern void overlay_plugin_walk(overlay_plugin_walk_f, void *);
199
200 extern void overlay_io_start(overlay_dev_t *, overlay_dev_flag_t);
201 extern void overlay_io_done(overlay_dev_t *, overlay_dev_flag_t);
202
203 extern void overlay_mux_init(void);
204 extern void overlay_mux_fini(void);
205
206 extern overlay_mux_t *overlay_mux_open(overlay_plugin_t *, int, int, int,
207 struct sockaddr *, socklen_t, int *);
208 extern void overlay_mux_close(overlay_mux_t *);
209 extern void overlay_mux_add_dev(overlay_mux_t *, overlay_dev_t *);
210 extern void overlay_mux_remove_dev(overlay_mux_t *, overlay_dev_t *);
211 extern int overlay_mux_tx(overlay_mux_t *, struct msghdr *, mblk_t *);
212
213 extern void overlay_prop_init(overlay_prop_handle_t);
214
215 extern void overlay_target_init(void);
216 extern int overlay_target_busy(void);
217 extern int overlay_target_open(dev_t *, int, int, cred_t *);
218 extern int overlay_target_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
219 extern int overlay_target_close(dev_t, int, int, cred_t *);
220 extern void overlay_target_free(overlay_dev_t *);
221
222 #define OVERLAY_TARGET_OK 0
223 #define OVERLAY_TARGET_DROP 1
224 #define OVERLAY_TARGET_ASYNC 2
225 extern int overlay_target_lookup(overlay_dev_t *, mblk_t *, struct sockaddr *,
226 socklen_t *);
227 extern void overlay_target_quiesce(overlay_target_t *);
228 extern void overlay_target_fini(void);
229
230 extern void overlay_fm_init(void);
231 extern void overlay_fm_fini(void);
232 extern void overlay_fm_degrade(overlay_dev_t *, const char *);
233 extern void overlay_fm_restore(overlay_dev_t *);
234
235 extern overlay_dev_t *overlay_hold_by_dlid(datalink_id_t);
236 extern void overlay_hold_rele(overlay_dev_t *);
237
238 #ifdef __cplusplus
239 }
240 #endif
241
242 #endif /* _SYS_OVERLAY_IMPL_H */