xref: /titanic_41/usr/src/uts/common/inet/nca/ncalogd.h (revision 6185db853e024a486ff8837e6784dd290d866112)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_INET_NCALOGD_H
28 #define	_INET_NCALOGD_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #define	MAX_URL_LEN	(8192)
37 
38 #define	NCA_DEFAULT_LOG_BUF_SIZE (65536)
39 
40 typedef struct log_buf {
41 	int8_t			buffer[NCA_DEFAULT_LOG_BUF_SIZE];
42 	uint32_t		size;
43 	uint32_t		cur_pos;
44 	struct log_buf		*next;
45 #ifndef _KERNEL
46 	mutex_t			log_lock;	/* threads-critical section */
47 #else
48 	kmutex_t		log_lock;	/* threads-critical section */
49 	frtn_t			ft;	/* free_func() for desballoc */
50 	void			*pad1;	/* padding so kernel and user-space */
51 	void			*pad2;	/* are the same size */
52 #endif /* _KERNEL */
53 } log_buf_t;
54 
55 /*
56  * Defines the data structures used by NCA and Webservers/log daemons.
57  */
58 
59 
60 typedef struct {
61 	ipaddr_t	remote_host;	/* IP address of the remote host */
62 
63 	/* size in bytes of nca_remote_user field */
64 	uint32_t	remote_user_len;
65 
66 	nca_offset_t	remote_user;
67 
68 	uint32_t	auth_user_len;
69 	nca_offset_t	auth_user;
70 #ifndef _KERNEL
71 	/* presumption: user space time_t is 32 bit long */
72 	time_t		start_process_time;
73 	time_t		end_process_time;
74 #else
75 	time32_t	start_process_time;
76 	time32_t	end_process_time;
77 #endif /* _KERNEL */
78 	/* length in bytes of first line of HTTP request */
79 	uint32_t	request_url_len;
80 
81 	nca_offset_t	request_url;
82 	uint32_t	response_status; /* cast to/from nca_http_status_code */
83 	uint32_t	response_len;
84 
85 	/* need for extended common log format */
86 	uint32_t	referer_len;
87 	nca_offset_t	referer;
88 	uint32_t	useragent_len;
89 	nca_offset_t	useragent;
90 
91 	/* Need for ELF */
92 	uint32_t	method;	/* must be cast to nca_http_method_t */
93 	uint32_t	version; /* request HTTP version */
94 
95 	/*
96 	 * This structure is optionally followed by null terminated strings
97 	 * that contain "remote_user","auth_user", etc.
98 	 */
99 } nca_request_log_t;
100 
101 typedef	struct {
102 	nca_version_t		nca_version;
103 	nca_op_t		nca_op;
104 } nca_ver_op_t;
105 
106 typedef struct {
107 	uint32_t	n_log_size;	/* size in bytes of log buf used */
108 	uint32_t	n_log_recs;	/* number of log recs in buffer */
109 	uint32_t	n_log_upcall;	/* NCA log buffer number */
110 } nca_log_stat_t;
111 
112 typedef struct {
113 	nca_ver_op_t		nca_loghdr;
114 	nca_log_stat_t		nca_logstats;
115 } nca_log_buf_hdr_t;
116 
117 /*
118  * log_op_fiov ...
119  */
120 
121 #include <sys/door.h>
122 
123 #define	NCA_FIOV_SZ	16
124 
125 typedef struct {
126 	struct {
127 		int	ix;		/* Current log file [ix] */
128 		int	cnt;		/* Count of valid log file [ix]s */
129 	} hdr;
130 	struct {
131 		vnode_t	*vp;		/* The vnode pointer for the file */
132 		off64_t	size;		/* Configured maximum bytes to write */
133 		off64_t	offset;		/* Offset in fd for next write */
134 		int	file;		/* Index of file (for reference only) */
135 		caddr_t	name;		/* The name of file */
136 	} iov[NCA_FIOV_SZ];		/* The iov's for each desc[] */
137 	vnode_t	*dvp;			/* vnode of dir where symlink lives */
138 } nca_fio_t;
139 
140 #define	nca_fio_vp(fiop)	(fiop)->iov[(fiop)->hdr.ix].vp
141 #define	nca_fio_name(fiop)	(fiop)->iov[(fiop)->hdr.ix].name
142 #define	nca_fio_size(fiop)	(fiop)->iov[(fiop)->hdr.ix].size
143 #define	nca_fio_offset(fiop)	(fiop)->iov[(fiop)->hdr.ix].offset
144 #define	nca_fio_file(fiop)	(fiop)->iov[(fiop)->hdr.ix].file
145 #define	nca_fio_ix(fiop)	(fiop)->hdr.ix
146 #define	nca_fio_cnt(fiop)	(fiop)->hdr.cnt
147 #define	nca_fio_dvp(fiop)	(fiop)->dvp
148 
149 #define	nca_fio_nxt_name(fiop)		(fiop)->iov[(fiop)->hdr.cnt].name
150 #define	nca_fio_nxt_size(fiop)		(fiop)->iov[(fiop)->hdr.cnt].size
151 #define	nca_fio_nxt_offset(fiop)	(fiop)->iov[(fiop)->hdr.cnt].offset
152 #define	nca_fio_nxt_file(fiop)		(fiop)->iov[(fiop)->hdr.cnt].file
153 
154 typedef struct {
155 	nca_ver_op_t		hdr;
156 	nca_fio_t		fio;
157 } nca_log_fio_hdr_t;
158 
159 /*
160  *	Macro to get size of a log record
161  */
162 #define	NCA_LOG_REC_SIZE(p)	 (sizeof (nca_request_log_t) + \
163 					p->remote_user_len + \
164 					p->auth_user_len + \
165 					p->request_url_len + \
166 					p->referer_len + p->useragent_len)
167 
168 /*
169  *	Used to align start of log record on a uint32_t boundary .
170  */
171 #define	NCA_LOG_ALIGN(p)	(char *)(((size_t)p+(sizeof (uint32_t)-1)) & \
172 						~(sizeof (uint32_t)-1))
173 
174 /*
175  *	Macros to get at char string data given a pointer to a
176  *	nca_request_log_t structure.
177  */
178 #define	NCA_REQLOG_RDATA(p, name) ((char *)p + sizeof (nca_request_log_t) + \
179 					(p->name))
180 
181 /* write data as offsets at end of nca_request_log_t buf */
182 #define	NCA_REQLOG_WDATA(val, p, n_used, len, off) {	\
183 	if (!(val)) {					\
184 		p->len = 0;				\
185 		p->off = 0;				\
186 	} else {					\
187 		p->len = strlen(val) + 1;		\
188 		bcopy(val, ((char *)p + sizeof (nca_request_log_t) \
189 				+ n_used), (p->len));	\
190 		p->off = n_used;			\
191 		n_used += (p->len);			\
192 		}					\
193 }
194 
195 #ifdef	__cplusplus
196 }
197 #endif
198 
199 #endif /* _INET_NCALOGD_H */
200