summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/inet/nca/ncalogd.h
blob: 793371a9b1736dd36e3763386ec692542dea0983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_INET_NCALOGD_H
#define	_INET_NCALOGD_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#ifdef	__cplusplus
extern "C" {
#endif

#define	MAX_URL_LEN	(8192)

#define	NCA_DEFAULT_LOG_BUF_SIZE (65536)

typedef struct log_buf {
	int8_t			buffer[NCA_DEFAULT_LOG_BUF_SIZE];
	uint32_t		size;
	uint32_t		cur_pos;
	struct log_buf		*next;
#ifndef _KERNEL
	mutex_t			log_lock;	/* threads-critical section */
#else
	kmutex_t		log_lock;	/* threads-critical section */
	frtn_t			ft;	/* free_func() for desballoc */
	void			*pad1;	/* padding so kernel and user-space */
	void			*pad2;	/* are the same size */
#endif /* _KERNEL */
} log_buf_t;

/*
 * Defines the data structures used by NCA and Webservers/log daemons.
 */


typedef struct {
	ipaddr_t	remote_host;	/* IP address of the remote host */

	/* size in bytes of nca_remote_user field */
	uint32_t	remote_user_len;

	nca_offset_t	remote_user;

	uint32_t	auth_user_len;
	nca_offset_t	auth_user;
#ifndef _KERNEL
	/* presumption: user space time_t is 32 bit long */
	time_t		start_process_time;
	time_t		end_process_time;
#else
	time32_t	start_process_time;
	time32_t	end_process_time;
#endif /* _KERNEL */
	/* length in bytes of first line of HTTP request */
	uint32_t	request_url_len;

	nca_offset_t	request_url;
	uint32_t	response_status; /* cast to/from nca_http_status_code */
	uint32_t	response_len;

	/* need for extended common log format */
	uint32_t	referer_len;
	nca_offset_t	referer;
	uint32_t	useragent_len;
	nca_offset_t	useragent;

	/* Need for ELF */
	uint32_t	method;	/* must be cast to nca_http_method_t */
	uint32_t	version; /* request HTTP version */

	/*
	 * This structure is optionally followed by null terminated strings
	 * that contain "remote_user","auth_user", etc.
	 */
} nca_request_log_t;

typedef	struct {
	nca_version_t		nca_version;
	nca_op_t		nca_op;
} nca_ver_op_t;

typedef struct {
	uint32_t	n_log_size;	/* size in bytes of log buf used */
	uint32_t	n_log_recs;	/* number of log recs in buffer */
	uint32_t	n_log_upcall;	/* NCA log buffer number */
} nca_log_stat_t;

typedef struct {
	nca_ver_op_t		nca_loghdr;
	nca_log_stat_t		nca_logstats;
} nca_log_buf_hdr_t;

/*
 * log_op_fiov ...
 */

#include <sys/door.h>

#ifdef _KERNEL
#define	NCA_FIOV_SZ	16

typedef struct {
	struct {
		int	ix;		/* Current log file [ix] */
		int	cnt;		/* Count of valid log file [ix]s */
	} hdr;
	struct {
		vnode_t	*vp;		/* The vnode pointer for the file */
		off64_t	size;		/* Configured maximum bytes to write */
		off64_t	offset;		/* Offset in fd for next write */
		int	file;		/* Index of file (for reference only) */
		caddr_t	name;		/* The name of file */
	} iov[NCA_FIOV_SZ];		/* The iov's for each desc[] */
	vnode_t	*dvp;			/* vnode of dir where symlink lives */
} nca_fio_t;

#define	nca_fio_vp(fiop)	(fiop)->iov[(fiop)->hdr.ix].vp
#define	nca_fio_name(fiop)	(fiop)->iov[(fiop)->hdr.ix].name
#define	nca_fio_size(fiop)	(fiop)->iov[(fiop)->hdr.ix].size
#define	nca_fio_offset(fiop)	(fiop)->iov[(fiop)->hdr.ix].offset
#define	nca_fio_file(fiop)	(fiop)->iov[(fiop)->hdr.ix].file
#define	nca_fio_ix(fiop)	(fiop)->hdr.ix
#define	nca_fio_cnt(fiop)	(fiop)->hdr.cnt
#define	nca_fio_dvp(fiop)	(fiop)->dvp
#endif /* _KERNEL */

/*
 *	Macro to get size of a log record
 */
#define	NCA_LOG_REC_SIZE(p)	 (sizeof (nca_request_log_t) + \
					p->remote_user_len + \
					p->auth_user_len + \
					p->request_url_len + \
					p->referer_len + p->useragent_len)

/*
 *	Used to align start of log record on a uint32_t boundary .
 */
#define	NCA_LOG_ALIGN(p)	(char *)(((size_t)p+(sizeof (uint32_t)-1)) & \
						~(sizeof (uint32_t)-1))

/*
 *	Macros to get at char string data given a pointer to a
 *	nca_request_log_t structure.
 */
#define	NCA_REQLOG_RDATA(p, name) ((char *)p + sizeof (nca_request_log_t) + \
					(p->name))

/* write data as offsets at end of nca_request_log_t buf */
#define	NCA_REQLOG_WDATA(val, p, n_used, len, off) {	\
	if (!(val)) {					\
		p->len = 0;				\
		p->off = 0;				\
	} else {					\
		p->len = strlen(val) + 1;		\
		bcopy(val, ((char *)p + sizeof (nca_request_log_t) \
				+ n_used), (p->len));	\
		p->off = n_used;			\
		n_used += (p->len);			\
		}					\
}

#ifdef	__cplusplus
}
#endif

#endif /* _INET_NCALOGD_H */