xref: /titanic_51/usr/src/uts/common/inet/nca/ncalogd.h (revision 458cf4d67cff5ff99a68a866b7657f1b1d6fe61c)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_INET_NCALOGD_H
27 #define	_INET_NCALOGD_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #define	MAX_URL_LEN	(8192)
36 
37 #define	NCA_DEFAULT_LOG_BUF_SIZE (65536)
38 
39 typedef struct log_buf {
40 	int8_t			buffer[NCA_DEFAULT_LOG_BUF_SIZE];
41 	uint32_t		size;
42 	uint32_t		cur_pos;
43 	struct log_buf		*next;
44 #ifndef _KERNEL
45 	mutex_t			log_lock;	/* threads-critical section */
46 #else
47 	kmutex_t		log_lock;	/* threads-critical section */
48 	frtn_t			ft;	/* free_func() for desballoc */
49 	void			*pad1;	/* padding so kernel and user-space */
50 	void			*pad2;	/* are the same size */
51 #endif /* _KERNEL */
52 } log_buf_t;
53 
54 /*
55  * Defines the data structures used by NCA and Webservers/log daemons.
56  */
57 
58 
59 typedef struct {
60 	ipaddr_t	remote_host;	/* IP address of the remote host */
61 
62 	/* size in bytes of nca_remote_user field */
63 	uint32_t	remote_user_len;
64 
65 	nca_offset_t	remote_user;
66 
67 	uint32_t	auth_user_len;
68 	nca_offset_t	auth_user;
69 #ifndef _KERNEL
70 	/* presumption: user space time_t is 32 bit long */
71 	time_t		start_process_time;
72 	time_t		end_process_time;
73 #else
74 	time32_t	start_process_time;
75 	time32_t	end_process_time;
76 #endif /* _KERNEL */
77 	/* length in bytes of first line of HTTP request */
78 	uint32_t	request_url_len;
79 
80 	nca_offset_t	request_url;
81 	uint32_t	response_status; /* cast to/from nca_http_status_code */
82 	uint32_t	response_len;
83 
84 	/* need for extended common log format */
85 	uint32_t	referer_len;
86 	nca_offset_t	referer;
87 	uint32_t	useragent_len;
88 	nca_offset_t	useragent;
89 
90 	/* Need for ELF */
91 	uint32_t	method;	/* must be cast to nca_http_method_t */
92 	uint32_t	version; /* request HTTP version */
93 
94 	/*
95 	 * This structure is optionally followed by null terminated strings
96 	 * that contain "remote_user","auth_user", etc.
97 	 */
98 } nca_request_log_t;
99 
100 typedef	struct {
101 	nca_version_t		nca_version;
102 	nca_op_t		nca_op;
103 } nca_ver_op_t;
104 
105 typedef struct {
106 	uint32_t	n_log_size;	/* size in bytes of log buf used */
107 	uint32_t	n_log_recs;	/* number of log recs in buffer */
108 	uint32_t	n_log_upcall;	/* NCA log buffer number */
109 } nca_log_stat_t;
110 
111 typedef struct {
112 	nca_ver_op_t		nca_loghdr;
113 	nca_log_stat_t		nca_logstats;
114 } nca_log_buf_hdr_t;
115 
116 /*
117  * log_op_fiov ...
118  */
119 
120 #include <sys/door.h>
121 
122 #ifdef _KERNEL
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 #endif /* _KERNEL */
149 
150 /*
151  *	Macro to get size of a log record
152  */
153 #define	NCA_LOG_REC_SIZE(p)	 (sizeof (nca_request_log_t) + \
154 					p->remote_user_len + \
155 					p->auth_user_len + \
156 					p->request_url_len + \
157 					p->referer_len + p->useragent_len)
158 
159 /*
160  *	Used to align start of log record on a uint32_t boundary .
161  */
162 #define	NCA_LOG_ALIGN(p)	(char *)(((size_t)p+(sizeof (uint32_t)-1)) & \
163 						~(sizeof (uint32_t)-1))
164 
165 /*
166  *	Macros to get at char string data given a pointer to a
167  *	nca_request_log_t structure.
168  */
169 #define	NCA_REQLOG_RDATA(p, name) ((char *)p + sizeof (nca_request_log_t) + \
170 					(p->name))
171 
172 /* write data as offsets at end of nca_request_log_t buf */
173 #define	NCA_REQLOG_WDATA(val, p, n_used, len, off) {	\
174 	if (!(val)) {					\
175 		p->len = 0;				\
176 		p->off = 0;				\
177 	} else {					\
178 		p->len = strlen(val) + 1;		\
179 		bcopy(val, ((char *)p + sizeof (nca_request_log_t) \
180 				+ n_used), (p->len));	\
181 		p->off = n_used;			\
182 		n_used += (p->len);			\
183 		}					\
184 }
185 
186 #ifdef	__cplusplus
187 }
188 #endif
189 
190 #endif /* _INET_NCALOGD_H */
191