xref: /onnv-gate/usr/src/uts/common/inet/nca/ncalogd.h (revision 5006:304eb1332eef)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*5006Sek110237  * Common Development and Distribution License (the "License").
6*5006Sek110237  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*5006Sek110237  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_INET_NCALOGD_H
270Sstevel@tonic-gate #define	_INET_NCALOGD_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate #ifdef	__cplusplus
320Sstevel@tonic-gate extern "C" {
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #define	MAX_URL_LEN	(8192)
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #define	NCA_DEFAULT_LOG_BUF_SIZE (65536)
380Sstevel@tonic-gate 
390Sstevel@tonic-gate typedef struct log_buf {
400Sstevel@tonic-gate 	int8_t			buffer[NCA_DEFAULT_LOG_BUF_SIZE];
410Sstevel@tonic-gate 	uint32_t		size;
420Sstevel@tonic-gate 	uint32_t		cur_pos;
430Sstevel@tonic-gate 	struct log_buf		*next;
440Sstevel@tonic-gate #ifndef _KERNEL
450Sstevel@tonic-gate 	mutex_t			log_lock;	/* threads-critical section */
460Sstevel@tonic-gate #else
470Sstevel@tonic-gate 	kmutex_t		log_lock;	/* threads-critical section */
480Sstevel@tonic-gate 	frtn_t			ft;	/* free_func() for desballoc */
490Sstevel@tonic-gate 	void			*pad1;	/* padding so kernel and user-space */
500Sstevel@tonic-gate 	void			*pad2;	/* are the same size */
510Sstevel@tonic-gate #endif /* _KERNEL */
520Sstevel@tonic-gate } log_buf_t;
530Sstevel@tonic-gate 
540Sstevel@tonic-gate /*
550Sstevel@tonic-gate  * Defines the data structures used by NCA and Webservers/log daemons.
560Sstevel@tonic-gate  */
570Sstevel@tonic-gate 
580Sstevel@tonic-gate 
590Sstevel@tonic-gate typedef struct {
600Sstevel@tonic-gate 	ipaddr_t	remote_host;	/* IP address of the remote host */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate 	/* size in bytes of nca_remote_user field */
630Sstevel@tonic-gate 	uint32_t	remote_user_len;
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	nca_offset_t	remote_user;
660Sstevel@tonic-gate 
670Sstevel@tonic-gate 	uint32_t	auth_user_len;
680Sstevel@tonic-gate 	nca_offset_t	auth_user;
690Sstevel@tonic-gate #ifndef _KERNEL
700Sstevel@tonic-gate 	/* presumption: user space time_t is 32 bit long */
710Sstevel@tonic-gate 	time_t		start_process_time;
720Sstevel@tonic-gate 	time_t		end_process_time;
730Sstevel@tonic-gate #else
740Sstevel@tonic-gate 	time32_t	start_process_time;
750Sstevel@tonic-gate 	time32_t	end_process_time;
760Sstevel@tonic-gate #endif /* _KERNEL */
770Sstevel@tonic-gate 	/* length in bytes of first line of HTTP request */
780Sstevel@tonic-gate 	uint32_t	request_url_len;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	nca_offset_t	request_url;
810Sstevel@tonic-gate 	uint32_t	response_status; /* cast to/from nca_http_status_code */
820Sstevel@tonic-gate 	uint32_t	response_len;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	/* need for extended common log format */
850Sstevel@tonic-gate 	uint32_t	referer_len;
860Sstevel@tonic-gate 	nca_offset_t	referer;
870Sstevel@tonic-gate 	uint32_t	useragent_len;
880Sstevel@tonic-gate 	nca_offset_t	useragent;
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	/* Need for ELF */
910Sstevel@tonic-gate 	uint32_t	method;	/* must be cast to nca_http_method_t */
920Sstevel@tonic-gate 	uint32_t	version; /* request HTTP version */
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	/*
950Sstevel@tonic-gate 	 * This structure is optionally followed by null terminated strings
960Sstevel@tonic-gate 	 * that contain "remote_user","auth_user", etc.
970Sstevel@tonic-gate 	 */
980Sstevel@tonic-gate } nca_request_log_t;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate typedef	struct {
1010Sstevel@tonic-gate 	nca_version_t		nca_version;
1020Sstevel@tonic-gate 	nca_op_t		nca_op;
1030Sstevel@tonic-gate } nca_ver_op_t;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate typedef struct {
1060Sstevel@tonic-gate 	uint32_t	n_log_size;	/* size in bytes of log buf used */
1070Sstevel@tonic-gate 	uint32_t	n_log_recs;	/* number of log recs in buffer */
1080Sstevel@tonic-gate 	uint32_t	n_log_upcall;	/* NCA log buffer number */
1090Sstevel@tonic-gate } nca_log_stat_t;
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate typedef struct {
1120Sstevel@tonic-gate 	nca_ver_op_t		nca_loghdr;
1130Sstevel@tonic-gate 	nca_log_stat_t		nca_logstats;
1140Sstevel@tonic-gate } nca_log_buf_hdr_t;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate  * log_op_fiov ...
1180Sstevel@tonic-gate  */
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate #include <sys/door.h>
1210Sstevel@tonic-gate 
122*5006Sek110237 #ifdef _KERNEL
1230Sstevel@tonic-gate #define	NCA_FIOV_SZ	16
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate typedef struct {
1260Sstevel@tonic-gate 	struct {
1270Sstevel@tonic-gate 		int	ix;		/* Current log file [ix] */
1280Sstevel@tonic-gate 		int	cnt;		/* Count of valid log file [ix]s */
1290Sstevel@tonic-gate 	} hdr;
1300Sstevel@tonic-gate 	struct {
1310Sstevel@tonic-gate 		vnode_t	*vp;		/* The vnode pointer for the file */
1320Sstevel@tonic-gate 		off64_t	size;		/* Configured maximum bytes to write */
1330Sstevel@tonic-gate 		off64_t	offset;		/* Offset in fd for next write */
1340Sstevel@tonic-gate 		int	file;		/* Index of file (for reference only) */
1350Sstevel@tonic-gate 		caddr_t	name;		/* The name of file */
1360Sstevel@tonic-gate 	} iov[NCA_FIOV_SZ];		/* The iov's for each desc[] */
1370Sstevel@tonic-gate 	vnode_t	*dvp;			/* vnode of dir where symlink lives */
1380Sstevel@tonic-gate } nca_fio_t;
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate #define	nca_fio_vp(fiop)	(fiop)->iov[(fiop)->hdr.ix].vp
1410Sstevel@tonic-gate #define	nca_fio_name(fiop)	(fiop)->iov[(fiop)->hdr.ix].name
1420Sstevel@tonic-gate #define	nca_fio_size(fiop)	(fiop)->iov[(fiop)->hdr.ix].size
1430Sstevel@tonic-gate #define	nca_fio_offset(fiop)	(fiop)->iov[(fiop)->hdr.ix].offset
1440Sstevel@tonic-gate #define	nca_fio_file(fiop)	(fiop)->iov[(fiop)->hdr.ix].file
1450Sstevel@tonic-gate #define	nca_fio_ix(fiop)	(fiop)->hdr.ix
1460Sstevel@tonic-gate #define	nca_fio_cnt(fiop)	(fiop)->hdr.cnt
1470Sstevel@tonic-gate #define	nca_fio_dvp(fiop)	(fiop)->dvp
148*5006Sek110237 #endif /* _KERNEL */
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate /*
1510Sstevel@tonic-gate  *	Macro to get size of a log record
1520Sstevel@tonic-gate  */
1530Sstevel@tonic-gate #define	NCA_LOG_REC_SIZE(p)	 (sizeof (nca_request_log_t) + \
1540Sstevel@tonic-gate 					p->remote_user_len + \
1550Sstevel@tonic-gate 					p->auth_user_len + \
1560Sstevel@tonic-gate 					p->request_url_len + \
1570Sstevel@tonic-gate 					p->referer_len + p->useragent_len)
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate  *	Used to align start of log record on a uint32_t boundary .
1610Sstevel@tonic-gate  */
1620Sstevel@tonic-gate #define	NCA_LOG_ALIGN(p)	(char *)(((size_t)p+(sizeof (uint32_t)-1)) & \
1630Sstevel@tonic-gate 						~(sizeof (uint32_t)-1))
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate /*
1660Sstevel@tonic-gate  *	Macros to get at char string data given a pointer to a
1670Sstevel@tonic-gate  *	nca_request_log_t structure.
1680Sstevel@tonic-gate  */
1690Sstevel@tonic-gate #define	NCA_REQLOG_RDATA(p, name) ((char *)p + sizeof (nca_request_log_t) + \
1700Sstevel@tonic-gate 					(p->name))
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate /* write data as offsets at end of nca_request_log_t buf */
1730Sstevel@tonic-gate #define	NCA_REQLOG_WDATA(val, p, n_used, len, off) {	\
1740Sstevel@tonic-gate 	if (!(val)) {					\
1750Sstevel@tonic-gate 		p->len = 0;				\
1760Sstevel@tonic-gate 		p->off = 0;				\
1770Sstevel@tonic-gate 	} else {					\
1780Sstevel@tonic-gate 		p->len = strlen(val) + 1;		\
1790Sstevel@tonic-gate 		bcopy(val, ((char *)p + sizeof (nca_request_log_t) \
1800Sstevel@tonic-gate 				+ n_used), (p->len));	\
1810Sstevel@tonic-gate 		p->off = n_used;			\
1820Sstevel@tonic-gate 		n_used += (p->len);			\
1830Sstevel@tonic-gate 		}					\
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate #ifdef	__cplusplus
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate #endif
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate #endif /* _INET_NCALOGD_H */
191