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