xref: /openbsd/usr.sbin/tcpdump/nfsv2.h (revision 29295d1c)
1 /*	$OpenBSD: nfsv2.h,v 1.7 2003/06/02 23:36:54 millert Exp $	*/
2 
3 /*
4  * Copyright (c) 1994, 1995, 1996
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Rick Macklem at The University of Guelph.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *	@(#)nfsv2.h	7.11 (Berkeley) 9/30/92
35  */
36 
37 /*
38  * nfs definitions as per the version 2 specs
39  */
40 
41 /*
42  * Constants as defined in the Sun NFS Version 2 spec.
43  * "NFS: Network File System Protocol Specification" RFC1094
44  */
45 
46 #define NFS_PORT	2049
47 #define	NFS_PROG	100003
48 #define NFS_VER2	2
49 #define	NFS_MAXDGRAMDATA 8192
50 #define	NFS_MAXDATA	32768
51 #define	NFS_MAXPATHLEN	1024
52 #define	NFS_MAXNAMLEN	255
53 #define	NFS_FHSIZE	32
54 #define	NFS_MAXPKTHDR	404
55 #define NFS_MAXPACKET	(NFS_MAXPKTHDR+NFS_MAXDATA)
56 #define	NFS_MINPACKET	20
57 #define	NFS_FABLKSIZE	512	/* Size in bytes of a block wrt fa_blocks */
58 
59 /* Stat numbers for rpc returns */
60 #define	NFS_OK		0
61 #define	NFSERR_PERM	1
62 #define	NFSERR_NOENT	2
63 #define	NFSERR_IO	5
64 #define	NFSERR_NXIO	6
65 #define	NFSERR_ACCES	13
66 #define	NFSERR_EXIST	17
67 #define	NFSERR_NODEV	19
68 #define	NFSERR_NOTDIR	20
69 #define	NFSERR_ISDIR	21
70 #define	NFSERR_FBIG	27
71 #define	NFSERR_NOSPC	28
72 #define	NFSERR_ROFS	30
73 #define	NFSERR_NAMETOL	63
74 #define	NFSERR_NOTEMPTY	66
75 #define	NFSERR_DQUOT	69
76 #define	NFSERR_STALE	70
77 #define	NFSERR_WFLUSH	99
78 
79 /* Sizes in bytes of various nfs rpc components */
80 #define	NFSX_FH		32
81 #define	NFSX_UNSIGNED	4
82 #define	NFSX_NFSFATTR	68
83 #define	NFSX_NQFATTR	92
84 #define	NFSX_NFSSATTR	32
85 #define	NFSX_NQSATTR	44
86 #define	NFSX_COOKIE	4
87 #define NFSX_NFSSTATFS	20
88 #define	NFSX_NQSTATFS	28
89 #define	NFSX_FATTR(isnq)	((isnq) ? NFSX_NQFATTR : NFSX_NFSFATTR)
90 #define	NFSX_SATTR(isnq)	((isnq) ? NFSX_NQSATTR : NFSX_NFSSATTR)
91 #define	NFSX_STATFS(isnq)	((isnq) ? NFSX_NQSTATFS : NFSX_NFSSTATFS)
92 
93 /* nfs rpc procedure numbers */
94 #define	NFSPROC_NULL		0
95 #define	NFSPROC_GETATTR		1
96 #define	NFSPROC_SETATTR		2
97 #define	NFSPROC_NOOP		3
98 #define	NFSPROC_ROOT		NFSPROC_NOOP	/* Obsolete */
99 #define	NFSPROC_LOOKUP		4
100 #define	NFSPROC_READLINK	5
101 #define	NFSPROC_READ		6
102 #define	NFSPROC_WRITECACHE	NFSPROC_NOOP	/* Obsolete */
103 #define	NFSPROC_WRITE		8
104 #define	NFSPROC_CREATE		9
105 #define	NFSPROC_REMOVE		10
106 #define	NFSPROC_RENAME		11
107 #define	NFSPROC_LINK		12
108 #define	NFSPROC_SYMLINK		13
109 #define	NFSPROC_MKDIR		14
110 #define	NFSPROC_RMDIR		15
111 #define	NFSPROC_READDIR		16
112 #define	NFSPROC_STATFS		17
113 
114 /* NQ nfs numbers */
115 #define	NQNFSPROC_READDIRLOOK	18
116 #define	NQNFSPROC_GETLEASE	19
117 #define	NQNFSPROC_VACATED	20
118 #define	NQNFSPROC_EVICTED	21
119 #define	NQNFSPROC_ACCESS	22
120 
121 #define	NFS_NPROCS		23
122 /* Conversion macros */
123 extern int		vttoif_tab[];
124 #define	vtonfs_mode(t,m) \
125 		txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \
126 				MAKEIMODE((t), (m)))
127 #define	nfstov_mode(a)	(fxdr_unsigned(u_short, (a))&07777)
128 #define	vtonfs_type(a)	txdr_unsigned(nfs_type[((int32_t)(a))])
129 #define	nfstov_type(a)	ntov_type[fxdr_unsigned(u_int32_t,(a))&0x7]
130 
131 /* File types */
132 typedef enum {
133     NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5
134 } tcpdump_nfstype;
135 
136 /* Structs for common parts of the rpc's */
137 struct nfsv2_time {
138 	u_int32_t nfs_sec;
139 	u_int32_t nfs_usec;
140 };
141 
142 struct nqnfs_time {
143 	u_int32_t nq_sec;
144 	u_int32_t nq_nsec;
145 };
146 
147 /*
148  * File attributes and setable attributes. These structures cover both
149  * NFS version 2 and the NQNFS protocol. Note that the union is only
150  * used to that one pointer can refer to both variants. These structures
151  * go out on the wire and must be densely packed, so no quad data types
152  * are used. (all fields are int32_t or u_int32_t's or structures of same)
153  * NB: You can't do sizeof(struct nfsv2_fattr), you must use the
154  *     NFSX_FATTR(isnq) macro.
155  */
156 struct nfsv2_fattr {
157 	u_int32_t fa_type;
158 	u_int32_t fa_mode;
159 	u_int32_t fa_nlink;
160 	u_int32_t fa_uid;
161 	u_int32_t fa_gid;
162 	union {
163 		struct {
164 			u_int32_t nfsfa_size;
165 			u_int32_t nfsfa_blocksize;
166 			u_int32_t nfsfa_rdev;
167 			u_int32_t nfsfa_blocks;
168 			u_int32_t nfsfa_fsid;
169 			u_int32_t nfsfa_fileid;
170 			struct nfsv2_time nfsfa_atime;
171 			struct nfsv2_time nfsfa_mtime;
172 			struct nfsv2_time nfsfa_ctime;
173 		} fa_nfsv2;
174 		struct {
175 			struct {
176 				u_int32_t nqfa_qsize[2];
177 			} nqfa_size;
178 			u_int32_t nqfa_blocksize;
179 			u_int32_t nqfa_rdev;
180 			struct {
181 				u_int32_t	nqfa_qbytes[2];
182 			} nqfa_bytes;
183 			u_int32_t nqfa_fsid;
184 			u_int32_t nqfa_fileid;
185 			struct nqnfs_time nqfa_atime;
186 			struct nqnfs_time nqfa_mtime;
187 			struct nqnfs_time nqfa_ctime;
188 			u_int32_t nqfa_flags;
189 			u_int32_t nqfa_gen;
190 			struct {
191 				u_int32_t nqfa_qfilerev[2];
192 			} nqfa_filerev;
193 		} fa_nqnfs;
194 	} fa_un;
195 };
196 
197 /* and some ugly defines for accessing union components */
198 #define	fa_nfssize		fa_un.fa_nfsv2.nfsfa_size
199 #define	fa_nfsblocksize		fa_un.fa_nfsv2.nfsfa_blocksize
200 #define	fa_nfsrdev		fa_un.fa_nfsv2.nfsfa_rdev
201 #define	fa_nfsblocks		fa_un.fa_nfsv2.nfsfa_blocks
202 #define	fa_nfsfsid		fa_un.fa_nfsv2.nfsfa_fsid
203 #define	fa_nfsfileid		fa_un.fa_nfsv2.nfsfa_fileid
204 #define	fa_nfsatime		fa_un.fa_nfsv2.nfsfa_atime
205 #define	fa_nfsmtime		fa_un.fa_nfsv2.nfsfa_mtime
206 #define	fa_nfsctime		fa_un.fa_nfsv2.nfsfa_ctime
207 #define	fa_nqsize		fa_un.fa_nqnfs.nqfa_size
208 #define	fa_nqblocksize		fa_un.fa_nqnfs.nqfa_blocksize
209 #define	fa_nqrdev		fa_un.fa_nqnfs.nqfa_rdev
210 #define	fa_nqbytes		fa_un.fa_nqnfs.nqfa_bytes
211 #define	fa_nqfsid		fa_un.fa_nqnfs.nqfa_fsid
212 #define	fa_nqfileid		fa_un.fa_nqnfs.nqfa_fileid
213 #define	fa_nqatime		fa_un.fa_nqnfs.nqfa_atime
214 #define	fa_nqmtime		fa_un.fa_nqnfs.nqfa_mtime
215 #define	fa_nqctime		fa_un.fa_nqnfs.nqfa_ctime
216 #define	fa_nqflags		fa_un.fa_nqnfs.nqfa_flags
217 #define	fa_nqgen		fa_un.fa_nqnfs.nqfa_gen
218 #define	fa_nqfilerev		fa_un.fa_nqnfs.nqfa_filerev
219 
220 struct nfsv2_sattr {
221 	u_int32_t sa_mode;
222 	u_int32_t sa_uid;
223 	u_int32_t sa_gid;
224 	union {
225 		struct {
226 			u_int32_t nfssa_size;
227 			struct nfsv2_time nfssa_atime;
228 			struct nfsv2_time nfssa_mtime;
229 		} sa_nfsv2;
230 		struct {
231 			struct {
232 				u_int32_t nqsa_qsize[2];
233 			} nqsa_size;
234 			struct nqnfs_time nqsa_atime;
235 			struct nqnfs_time nqsa_mtime;
236 			u_int32_t nqsa_flags;
237 			u_int32_t nqsa_rdev;
238 		} sa_nqnfs;
239 	} sa_un;
240 };
241 
242 /* and some ugly defines for accessing the unions */
243 #define	sa_nfssize		sa_un.sa_nfsv2.nfssa_size
244 #define	sa_nfsatime		sa_un.sa_nfsv2.nfssa_atime
245 #define	sa_nfsmtime		sa_un.sa_nfsv2.nfssa_mtime
246 #define	sa_nqsize		sa_un.sa_nqnfs.nqsa_size
247 #define	sa_nqatime		sa_un.sa_nqnfs.nqsa_atime
248 #define	sa_nqmtime		sa_un.sa_nqnfs.nqsa_mtime
249 #define	sa_nqflags		sa_un.sa_nqnfs.nqsa_flags
250 #define	sa_nqrdev		sa_un.sa_nqnfs.nqsa_rdev
251 
252 struct nfsv2_statfs {
253 	u_int32_t sf_tsize;
254 	u_int32_t sf_bsize;
255 	u_int32_t sf_blocks;
256 	u_int32_t sf_bfree;
257 	u_int32_t sf_bavail;
258 	u_int32_t sf_files;	/* Nqnfs only */
259 	u_int32_t sf_ffree;	/* ditto      */
260 };
261