xref: /illumos-gate/usr/src/lib/libdladm/common/libdlstat.h (revision 66582b606a8194f7f3ba5b3a3a6dca5b0d346361)
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  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
28  */
29 
30 #ifndef _LIBDLSTAT_H
31 #define	_LIBDLSTAT_H
32 
33 /*
34  * This file includes structures, macros and common routines shared by all
35  * data-link administration, and routines which are used to retrieve and
36  * display statistics.
37  */
38 
39 #include <kstat.h>
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 #define	LINK_REPORT	1
46 #define	FLOW_REPORT	2
47 
48 #define	DLSTAT_INVALID_ENTRY	-1
49 #define	MAXSTATNAMELEN	256
50 /*
51  * Definitions common to all stats
52  */
53 typedef struct dladm_stat_chain_s {
54 	char				dc_statheader[MAXSTATNAMELEN];
55 	void				*dc_statentry;
56 	struct dladm_stat_chain_s	*dc_next;
57 } dladm_stat_chain_t;
58 
59 typedef enum {
60 	DLADM_STAT_RX_LANE = 0,		/* Per lane rx stats */
61 	DLADM_STAT_TX_LANE,		/* Per lane tx stats */
62 	DLADM_STAT_RX_LANE_TOTAL,	/* Stats summed across all rx lanes */
63 	DLADM_STAT_TX_LANE_TOTAL,	/* Stats summed across all tx lanes */
64 	DLADM_STAT_RX_LANE_FOUT,	/* Per fanout (rx lane) stats */
65 	DLADM_STAT_RX_RING,		/* Per ring rx stats */
66 	DLADM_STAT_TX_RING,		/* Per ring tx stats  */
67 	DLADM_STAT_RX_RING_TOTAL,	/* Stats summed across all rx rings */
68 	DLADM_STAT_TX_RING_TOTAL,	/* Stats summed across all tx rings */
69 	DLADM_STAT_TOTAL,		/* Summary view */
70 	DLADM_STAT_AGGR_PORT,		/* Aggr port stats */
71 	DLADM_STAT_MISC,		/* Misc stats */
72 	DLADM_STAT_NUM_STATS		/* This must always be the last entry */
73 } dladm_stat_type_t;
74 
75 /*
76  * Definitions for rx lane stats
77  */
78 typedef struct rx_lane_stat_s {
79 	uint64_t	rl_ipackets;
80 	uint64_t	rl_rbytes;
81 	uint64_t	rl_lclpackets;
82 	uint64_t	rl_lclbytes;
83 	uint64_t	rl_intrs;
84 	uint64_t	rl_intrbytes;
85 	uint64_t	rl_pollbytes;
86 	uint64_t	rl_polls;
87 	uint64_t	rl_sdrops;
88 	uint64_t	rl_chl10;
89 	uint64_t	rl_ch10_50;
90 	uint64_t	rl_chg50;
91 } rx_lane_stat_t;
92 
93 typedef enum {
94 	L_HWLANE,
95 	L_SWLANE,
96 	L_LOCAL,
97 	L_LCLSWLANE,
98 	L_BCAST,
99 	L_DFNCT
100 } lane_type_t;
101 
102 typedef struct rx_lane_stat_entry_s {
103 	int64_t		rle_index;
104 	lane_type_t	rle_id;
105 	rx_lane_stat_t	rle_stats;
106 } rx_lane_stat_entry_t;
107 
108 /*
109  * Definitions for tx lane stats
110  */
111 typedef struct tx_lane_stat_s {
112 	uint64_t	tl_opackets;
113 	uint64_t	tl_obytes;
114 	uint64_t	tl_blockcnt;
115 	uint64_t	tl_unblockcnt;
116 	uint64_t	tl_sdrops;
117 } tx_lane_stat_t;
118 
119 typedef struct tx_lane_stat_entry_s {
120 	int64_t		tle_index;
121 	lane_type_t	tle_id;
122 	tx_lane_stat_t	tle_stats;
123 } tx_lane_stat_entry_t;
124 
125 /*
126  * Definitions for tx/rx misc stats
127  */
128 typedef struct misc_stat_s {
129 	uint64_t	ms_multircv;
130 	uint64_t	ms_brdcstrcv;
131 	uint64_t	ms_multixmt;
132 	uint64_t	ms_brdcstxmt;
133 	uint64_t	ms_multircvbytes;
134 	uint64_t	ms_brdcstrcvbytes;
135 	uint64_t	ms_multixmtbytes;
136 	uint64_t	ms_brdcstxmtbytes;
137 	uint64_t	ms_txerrors;
138 	uint64_t	ms_macspoofed;
139 	uint64_t	ms_ipspoofed;
140 	uint64_t	ms_dhcpspoofed;
141 	uint64_t	ms_restricted;
142 	uint64_t	ms_dhcpdropped;
143 	uint64_t	ms_ipackets;
144 	uint64_t	ms_rbytes;
145 	uint64_t	ms_local;
146 	uint64_t	ms_localbytes;
147 	uint64_t	ms_intrs;
148 	uint64_t	ms_intrbytes;
149 	uint64_t	ms_polls;
150 	uint64_t	ms_pollbytes;
151 	uint64_t	ms_rxsdrops;
152 	uint64_t	ms_chainunder10;
153 	uint64_t	ms_chain10to50;
154 	uint64_t	ms_chainover50;
155 	uint64_t	ms_obytes;
156 	uint64_t	ms_opackets;
157 	uint64_t	ms_blockcnt;
158 	uint64_t	ms_unblockcnt;
159 	uint64_t	ms_txsdrops;
160 } misc_stat_t;
161 
162 /*
163  * To be consistent with other stat entries, misc stat
164  * is wrapped in stat entry
165  */
166 typedef struct misc_stat_entry_s {
167 	misc_stat_t	mse_stats;
168 } misc_stat_entry_t;
169 
170 /*
171  * Definitions for ring stats: used by rx as well as tx
172  */
173 typedef struct ring_stat_s {
174 	uint64_t	r_packets;
175 	uint64_t	r_bytes;
176 } ring_stat_t;
177 
178 typedef struct ring_stat_entry_s {
179 	int64_t		re_index;
180 	ring_stat_t	re_stats;
181 } ring_stat_entry_t;
182 
183 /*
184  * Definitions for fanout stats
185  */
186 typedef struct fanout_stat_s {
187 	uint64_t	f_ipackets;
188 	uint64_t	f_rbytes;
189 } fanout_stat_t;
190 
191 typedef struct fanout_stat_entry_s {
192 	int64_t		fe_index;
193 	lane_type_t	fe_id;		/* hw, sw, local */
194 	int64_t		fe_foutindex;	/* fanout index */
195 	fanout_stat_t	fe_stats;
196 } fanout_stat_entry_t;
197 
198 /*
199  * Definitions for total stats
200  */
201 typedef struct total_stat_s {
202 	uint64_t	ts_ipackets;
203 	uint64_t	ts_rbytes;
204 	uint64_t	ts_opackets;
205 	uint64_t	ts_obytes;
206 } total_stat_t;
207 
208 /*
209  * To be consistent with other stat entries, total stat
210  * is wrapped in stat entry
211  */
212 typedef struct total_stat_entry_s {
213 	total_stat_t	tse_stats;
214 } total_stat_entry_t;
215 
216 /*
217  * Definitions for aggr stats
218  */
219 typedef struct aggr_port_stat_s {
220 	uint64_t	ap_ipackets;
221 	uint64_t	ap_rbytes;
222 	uint64_t	ap_opackets;
223 	uint64_t	ap_obytes;
224 } aggr_port_stat_t;
225 
226 typedef struct aggr_port_stat_entry_s {
227 	datalink_id_t		ape_portlinkid;
228 	aggr_port_stat_t	ape_stats;
229 } aggr_port_stat_entry_t;
230 
231 /*
232  * Definitions for query all stats
233  */
234 typedef struct name_value_stat_s {
235 	char				nv_statname[MAXSTATNAMELEN];
236 	uint64_t			nv_statval;
237 	struct name_value_stat_s	*nv_nextstat;
238 } name_value_stat_t;
239 
240 typedef struct name_value_stat_entry_s {
241 	char			nve_header[MAXSTATNAMELEN];
242 	name_value_stat_t	*nve_stats;
243 } name_value_stat_entry_t;
244 
245 /*
246  * Definitions for flow stats
247  */
248 typedef struct flow_stat_s {
249 	uint64_t	fl_ipackets;
250 	uint64_t	fl_rbytes;
251 	uint64_t	fl_ierrors;
252 	uint64_t	fl_opackets;
253 	uint64_t	fl_obytes;
254 	uint64_t	fl_oerrors;
255 	uint64_t	fl_sdrops;
256 } flow_stat_t;
257 
258 typedef struct pktsum_s {
259 	hrtime_t	snaptime;
260 	uint64_t	ipackets;
261 	uint64_t	opackets;
262 	uint64_t	rbytes;
263 	uint64_t	obytes;
264 	uint64_t	ierrors;
265 	uint64_t	oerrors;
266 } pktsum_t;
267 
268 extern kstat_t		*dladm_kstat_lookup(kstat_ctl_t *, const char *, int,
269 			    const char *, const char *);
270 extern void		dladm_get_stats(kstat_ctl_t *, kstat_t *, pktsum_t *);
271 extern int		dladm_kstat_value(kstat_t *, const char *, uint8_t,
272 			    void *);
273 extern dladm_status_t	dladm_get_single_mac_stat(dladm_handle_t, datalink_id_t,
274 			    const char *, uint8_t, void *);
275 
276 extern void		dladm_stats_total(pktsum_t *, pktsum_t *, pktsum_t *);
277 extern void		dladm_stats_diff(pktsum_t *, pktsum_t *, pktsum_t *);
278 
279 extern dladm_stat_chain_t	*dladm_link_stat_query(dladm_handle_t,
280 				    datalink_id_t, dladm_stat_type_t);
281 extern dladm_stat_chain_t	*dladm_link_stat_diffchain(dladm_stat_chain_t *,
282 				    dladm_stat_chain_t *, dladm_stat_type_t);
283 extern dladm_stat_chain_t	*dladm_link_stat_query_all(dladm_handle_t,
284 				    datalink_id_t, dladm_stat_type_t);
285 
286 extern flow_stat_t		*dladm_flow_stat_query(dladm_handle_t,
287 				    const char *);
288 extern flow_stat_t		*dladm_flow_stat_diff(flow_stat_t *,
289 				    flow_stat_t *);
290 extern name_value_stat_entry_t	*dladm_flow_stat_query_all(dladm_handle_t,
291 				    const char *);
292 
293 #ifdef	__cplusplus
294 }
295 #endif
296 
297 #endif	/* _LIBDLSTAT_H */
298