xref: /illumos-gate/usr/src/lib/libdtrace/common/smb.d (revision a5a9a6bb70826a54a1c35d3b862a927fd22f7b0e)
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  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
27  * Copyright 2022 RackTop Systems, Inc.
28  */
29 
30 #pragma	D depends_on library ip.d
31 #pragma	D depends_on library net.d
32 #pragma	D depends_on module genunix
33 #pragma	D depends_on module smbsrv
34 
35 #pragma D binding "1.5" translator
36 translator conninfo_t < struct smb_request *P > {
37 	ci_protocol =
38 	    P->session->ipaddr.a_family == AF_INET6 ? "tcp6" :
39 	    P->session->ipaddr.a_family == AF_INET ? "tcp" :
40 	    "<unknown>";
41 	ci_local = "<any>"; /* not interesting */
42 	ci_remote = P->session->ip_addr_str;
43 };
44 
45 /*
46  * The smbopinfo_t structure describes the internal form of a
47  * single SMB request (SMB v1).
48  */
49 typedef struct smbopinfo {
50 	cred_t   *soi_cred;		/* credentials for operation */
51 	string   soi_share;		/* share name */
52 	string   soi_curpath;		/* file handle path (if any) */
53 	uint64_t soi_sid;		/* session id */
54 	uint32_t soi_pid;		/* process id */
55 	uint32_t soi_status;		/* status */
56 	uint16_t soi_tid;		/* tree id */
57 	uint16_t soi_uid;		/* user id */
58 	uint16_t soi_mid;		/* request id */
59 	uint16_t soi_fid;		/* file id */
60 	uint16_t soi_flags2;		/* flags2 */
61 	uint8_t  soi_flags;		/* flags */
62 	zoneid_t soi_zoneid;		/* zone identifier */
63 } smbopinfo_t;
64 
65 #pragma D binding "1.5" translator
66 translator smbopinfo_t < struct smb_request *P > {
67 	soi_cred	= (cred_t *)P->user_cr;
68 	soi_sid		= P->session->s_kid;
69 	soi_pid		= P->smb_pid;
70 	soi_status	= P->smb_error.status;
71 	soi_tid		= P->smb_tid;
72 	soi_uid		= P->smb_uid;
73 	soi_mid		= P->smb_mid;
74 	soi_fid		= P->smb_fid;
75 	soi_flags2	= P->smb_flg2;
76 	soi_flags	= P->smb_flg;
77 	soi_zoneid	= P->sr_server->sv_zid;
78 
79 	soi_share = (P->tid_tree == NULL) ? "<NULL>" :
80 	    P->tid_tree->t_sharename;
81 
82 	soi_curpath = (P->fid_ofile == NULL ||
83 	    P->fid_ofile->f_node == NULL ||
84 	    P->fid_ofile->f_node->vp == NULL ||
85 	    P->fid_ofile->f_node->vp->v_path == NULL) ? "<NULL>" :
86 	    P->fid_ofile->f_node->vp->v_path;
87 };
88 
89 typedef struct smb_rw_args {
90 	off_t	soa_offset;
91 	uint_t	soa_count;
92 } smb_rw_args_t;
93 
94 #pragma D binding "1.5" translator
95 translator smb_rw_args_t < smb_request_t *P > {
96 	soa_offset = P->arg.rw->rw_offset;
97 	soa_count  = P->arg.rw->rw_count;
98 };
99 
100 typedef struct smb_name_args {
101 	string	soa_name;
102 } smb_name_args_t;
103 
104 #pragma D binding "1.5" translator
105 translator smb_name_args_t < smb_request_t *P > {
106 	soa_name = (P->arg.dirop.fqi.fq_path.pn_path == NULL) ? "<NULL>" :
107 	    P->arg.dirop.fqi.fq_path.pn_path;
108 };
109 
110 typedef struct smb_open_args {
111 	string		soa_name;
112 	uint32_t	soa_desired_access;
113 	uint32_t	soa_share_access;
114 	uint32_t	soa_create_options;
115 	uint32_t	soa_create_disposition;
116 } smb_open_args_t;
117 
118 #pragma D binding "1.5" translator
119 translator smb_open_args_t < smb_request_t *P > {
120 	soa_name = (P->arg.open.fqi.fq_path.pn_path == NULL) ? "<NULL>" :
121 	    P->arg.open.fqi.fq_path.pn_path;
122 	soa_desired_access = P->arg.open.desired_access;
123 	soa_share_access   = P->arg.open.share_access;
124 	soa_create_options = P->arg.open.create_options;
125 	soa_create_disposition = P->arg.open.create_disposition;
126 };
127 
128 /*
129  * The smb2opinfo_t structure describes the internal form of a
130  * single SMB2 request (SMB v2 and later).
131  */
132 typedef struct smb2opinfo {
133 	cred_t   *soi_cred;		/* credentials for operation */
134 	string   soi_share;		/* share name */
135 	string   soi_curpath;		/* file handle path (if any) */
136 	uint64_t soi_sid;		/* (internal) session ID */
137 	uint64_t soi_mid;		/* Message ID */
138 	uint64_t soi_asyncid;		/* Message ID (when async) */
139 	uint64_t soi_uid;		/* user ID (SMB2 Session ID) */
140 	uint32_t soi_tid;		/* tree ID */
141 	uint32_t soi_fid;		/* file ID */
142 	uint32_t soi_status;
143 	uint32_t soi_flags;
144 	zoneid_t soi_zoneid;		/* zone identifier */
145 } smb2opinfo_t;
146 
147 #pragma D binding "1.5" translator
148 translator smb2opinfo_t < struct smb_request *P > {
149 	soi_cred	= (cred_t *)P->user_cr;
150 	soi_sid		= P->session->s_kid;
151 	soi_mid		= P->smb2_messageid;
152 	soi_asyncid	= P->smb2_async_id;
153 	soi_uid		= P->smb2_ssnid;
154 	soi_tid		= P->smb_tid;
155 	soi_fid		= P->smb_fid;
156 	soi_status	= P->smb2_status;
157 	soi_flags	= P->smb2_hdr_flags;
158 	soi_zoneid	= P->sr_server->sv_zid;
159 
160 	soi_share = (P->tid_tree == NULL) ? "<NULL>" :
161 	    P->tid_tree->t_sharename;
162 
163 	soi_curpath = (P->fid_ofile == NULL ||
164 	    P->fid_ofile->f_node == NULL ||
165 	    P->fid_ofile->f_node->vp == NULL ||
166 	    P->fid_ofile->f_node->vp->v_path == NULL) ? "<NULL>" :
167 	    P->fid_ofile->f_node->vp->v_path;
168 };
169