xref: /illumos-gate/usr/src/cmd/connstat/connstat.h (revision a2f04351)
1 /*
2  * CDDL HEADER START
3  *
4  * This file and its contents are supplied under the terms of the
5  * Common Development and Distribution License ("CDDL"), version 1.0.
6  * You may only use this file in accordance with the terms of version
7  * 1.0 of the CDDL.
8  *
9  * A full copy of the text of the CDDL should have accompanied this
10  * source.  A copy of the CDDL is also available via the Internet at
11  * http://www.illumos.org/license/CDDL.
12  *
13  * CDDL HEADER END
14  */
15 /*
16  * Copyright (c) 2015, 2016 by Delphix. All rights reserved.
17  */
18 
19 #ifndef	_CONNSTAT_H
20 #define	_CONNSTAT_H
21 
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <ofmt.h>
25 #include <sys/stropts.h>
26 
27 #ifdef	__cplusplus
28 extern "C" {
29 #endif
30 
31 typedef struct connstat_conn_attr_s {
32 	struct sockaddr_storage	ca_laddr;
33 	struct sockaddr_storage	ca_raddr;
34 	int			ca_lport;
35 	int			ca_rport;
36 	int			ca_state;
37 } connstat_conn_attr_t;
38 
39 typedef struct conn_walk_state_s {
40 	ofmt_handle_t		cws_ofmt;
41 	uint_t			cws_flags;
42 	connstat_conn_attr_t	cws_filter;
43 } conn_walk_state_t;
44 
45 /* cws_flags */
46 #define	CS_LOOPBACK	0x0001	/* Include loopback connections */
47 #define	CS_IPV4		0x0002	/* Show only IPv4 connections */
48 #define	CS_IPV6		0x0004	/* Show only IPv6 connections */
49 #define	CS_LADDR	0x0008	/* Filter by laddr in cws_filter */
50 #define	CS_RADDR	0x0010	/* Filter by raddr in cws_filter */
51 #define	CS_LPORT	0x0020	/* Filter by lport in cws_filter */
52 #define	CS_RPORT	0x0040	/* Filter by rport in cws_filter */
53 #define	CS_STATE	0x0080	/* Filter by state in cws_filter */
54 #define	CS_PARSABLE	0x0100	/* Parsable output */
55 
56 typedef ofmt_field_t *connstat_getfieldsfunc_t(void);
57 typedef void connstat_walkfunc_t(struct strbuf *, conn_walk_state_t *);
58 
59 typedef struct connstat_proto_s {
60 	char	*csp_proto;
61 	char	*csp_default_fields;
62 	int	csp_miblevel;
63 	int	csp_mibv4name;
64 	int	csp_mibv6name;
65 	connstat_getfieldsfunc_t *csp_getfields;
66 	connstat_walkfunc_t *csp_v4walk;
67 	connstat_walkfunc_t *csp_v6walk;
68 } connstat_proto_t;
69 
70 boolean_t print_string(ofmt_arg_t *, char *, uint_t);
71 boolean_t print_uint16(ofmt_arg_t *, char *, uint_t);
72 boolean_t print_uint32(ofmt_arg_t *, char *, uint_t);
73 boolean_t print_uint64(ofmt_arg_t *, char *, uint_t);
74 
75 #ifdef	__cplusplus
76 }
77 #endif
78 
79 #endif	/* _CONNSTAT_H */
80