xref: /titanic_50/usr/src/uts/common/inet/nca/ncalogd.h (revision 458cf4d67cff5ff99a68a866b7657f1b1d6fe61c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*458cf4d6Sek110237  * Common Development and Distribution License (the "License").
6*458cf4d6Sek110237  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*458cf4d6Sek110237  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_INET_NCALOGD_H
277c478bd9Sstevel@tonic-gate #define	_INET_NCALOGD_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #define	MAX_URL_LEN	(8192)
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #define	NCA_DEFAULT_LOG_BUF_SIZE (65536)
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate typedef struct log_buf {
407c478bd9Sstevel@tonic-gate 	int8_t			buffer[NCA_DEFAULT_LOG_BUF_SIZE];
417c478bd9Sstevel@tonic-gate 	uint32_t		size;
427c478bd9Sstevel@tonic-gate 	uint32_t		cur_pos;
437c478bd9Sstevel@tonic-gate 	struct log_buf		*next;
447c478bd9Sstevel@tonic-gate #ifndef _KERNEL
457c478bd9Sstevel@tonic-gate 	mutex_t			log_lock;	/* threads-critical section */
467c478bd9Sstevel@tonic-gate #else
477c478bd9Sstevel@tonic-gate 	kmutex_t		log_lock;	/* threads-critical section */
487c478bd9Sstevel@tonic-gate 	frtn_t			ft;	/* free_func() for desballoc */
497c478bd9Sstevel@tonic-gate 	void			*pad1;	/* padding so kernel and user-space */
507c478bd9Sstevel@tonic-gate 	void			*pad2;	/* are the same size */
517c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
527c478bd9Sstevel@tonic-gate } log_buf_t;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * Defines the data structures used by NCA and Webservers/log daemons.
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate typedef struct {
607c478bd9Sstevel@tonic-gate 	ipaddr_t	remote_host;	/* IP address of the remote host */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	/* size in bytes of nca_remote_user field */
637c478bd9Sstevel@tonic-gate 	uint32_t	remote_user_len;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	nca_offset_t	remote_user;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	uint32_t	auth_user_len;
687c478bd9Sstevel@tonic-gate 	nca_offset_t	auth_user;
697c478bd9Sstevel@tonic-gate #ifndef _KERNEL
707c478bd9Sstevel@tonic-gate 	/* presumption: user space time_t is 32 bit long */
717c478bd9Sstevel@tonic-gate 	time_t		start_process_time;
727c478bd9Sstevel@tonic-gate 	time_t		end_process_time;
737c478bd9Sstevel@tonic-gate #else
747c478bd9Sstevel@tonic-gate 	time32_t	start_process_time;
757c478bd9Sstevel@tonic-gate 	time32_t	end_process_time;
767c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
777c478bd9Sstevel@tonic-gate 	/* length in bytes of first line of HTTP request */
787c478bd9Sstevel@tonic-gate 	uint32_t	request_url_len;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	nca_offset_t	request_url;
817c478bd9Sstevel@tonic-gate 	uint32_t	response_status; /* cast to/from nca_http_status_code */
827c478bd9Sstevel@tonic-gate 	uint32_t	response_len;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	/* need for extended common log format */
857c478bd9Sstevel@tonic-gate 	uint32_t	referer_len;
867c478bd9Sstevel@tonic-gate 	nca_offset_t	referer;
877c478bd9Sstevel@tonic-gate 	uint32_t	useragent_len;
887c478bd9Sstevel@tonic-gate 	nca_offset_t	useragent;
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	/* Need for ELF */
917c478bd9Sstevel@tonic-gate 	uint32_t	method;	/* must be cast to nca_http_method_t */
927c478bd9Sstevel@tonic-gate 	uint32_t	version; /* request HTTP version */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	/*
957c478bd9Sstevel@tonic-gate 	 * This structure is optionally followed by null terminated strings
967c478bd9Sstevel@tonic-gate 	 * that contain "remote_user","auth_user", etc.
977c478bd9Sstevel@tonic-gate 	 */
987c478bd9Sstevel@tonic-gate } nca_request_log_t;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate typedef	struct {
1017c478bd9Sstevel@tonic-gate 	nca_version_t		nca_version;
1027c478bd9Sstevel@tonic-gate 	nca_op_t		nca_op;
1037c478bd9Sstevel@tonic-gate } nca_ver_op_t;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate typedef struct {
1067c478bd9Sstevel@tonic-gate 	uint32_t	n_log_size;	/* size in bytes of log buf used */
1077c478bd9Sstevel@tonic-gate 	uint32_t	n_log_recs;	/* number of log recs in buffer */
1087c478bd9Sstevel@tonic-gate 	uint32_t	n_log_upcall;	/* NCA log buffer number */
1097c478bd9Sstevel@tonic-gate } nca_log_stat_t;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate typedef struct {
1127c478bd9Sstevel@tonic-gate 	nca_ver_op_t		nca_loghdr;
1137c478bd9Sstevel@tonic-gate 	nca_log_stat_t		nca_logstats;
1147c478bd9Sstevel@tonic-gate } nca_log_buf_hdr_t;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * log_op_fiov ...
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #include <sys/door.h>
1217c478bd9Sstevel@tonic-gate 
122*458cf4d6Sek110237 #ifdef _KERNEL
1237c478bd9Sstevel@tonic-gate #define	NCA_FIOV_SZ	16
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate typedef struct {
1267c478bd9Sstevel@tonic-gate 	struct {
1277c478bd9Sstevel@tonic-gate 		int	ix;		/* Current log file [ix] */
1287c478bd9Sstevel@tonic-gate 		int	cnt;		/* Count of valid log file [ix]s */
1297c478bd9Sstevel@tonic-gate 	} hdr;
1307c478bd9Sstevel@tonic-gate 	struct {
1317c478bd9Sstevel@tonic-gate 		vnode_t	*vp;		/* The vnode pointer for the file */
1327c478bd9Sstevel@tonic-gate 		off64_t	size;		/* Configured maximum bytes to write */
1337c478bd9Sstevel@tonic-gate 		off64_t	offset;		/* Offset in fd for next write */
1347c478bd9Sstevel@tonic-gate 		int	file;		/* Index of file (for reference only) */
1357c478bd9Sstevel@tonic-gate 		caddr_t	name;		/* The name of file */
1367c478bd9Sstevel@tonic-gate 	} iov[NCA_FIOV_SZ];		/* The iov's for each desc[] */
1377c478bd9Sstevel@tonic-gate 	vnode_t	*dvp;			/* vnode of dir where symlink lives */
1387c478bd9Sstevel@tonic-gate } nca_fio_t;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	nca_fio_vp(fiop)	(fiop)->iov[(fiop)->hdr.ix].vp
1417c478bd9Sstevel@tonic-gate #define	nca_fio_name(fiop)	(fiop)->iov[(fiop)->hdr.ix].name
1427c478bd9Sstevel@tonic-gate #define	nca_fio_size(fiop)	(fiop)->iov[(fiop)->hdr.ix].size
1437c478bd9Sstevel@tonic-gate #define	nca_fio_offset(fiop)	(fiop)->iov[(fiop)->hdr.ix].offset
1447c478bd9Sstevel@tonic-gate #define	nca_fio_file(fiop)	(fiop)->iov[(fiop)->hdr.ix].file
1457c478bd9Sstevel@tonic-gate #define	nca_fio_ix(fiop)	(fiop)->hdr.ix
1467c478bd9Sstevel@tonic-gate #define	nca_fio_cnt(fiop)	(fiop)->hdr.cnt
1477c478bd9Sstevel@tonic-gate #define	nca_fio_dvp(fiop)	(fiop)->dvp
148*458cf4d6Sek110237 #endif /* _KERNEL */
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  *	Macro to get size of a log record
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate #define	NCA_LOG_REC_SIZE(p)	 (sizeof (nca_request_log_t) + \
1547c478bd9Sstevel@tonic-gate 					p->remote_user_len + \
1557c478bd9Sstevel@tonic-gate 					p->auth_user_len + \
1567c478bd9Sstevel@tonic-gate 					p->request_url_len + \
1577c478bd9Sstevel@tonic-gate 					p->referer_len + p->useragent_len)
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate  *	Used to align start of log record on a uint32_t boundary .
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate #define	NCA_LOG_ALIGN(p)	(char *)(((size_t)p+(sizeof (uint32_t)-1)) & \
1637c478bd9Sstevel@tonic-gate 						~(sizeof (uint32_t)-1))
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate  *	Macros to get at char string data given a pointer to a
1677c478bd9Sstevel@tonic-gate  *	nca_request_log_t structure.
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate #define	NCA_REQLOG_RDATA(p, name) ((char *)p + sizeof (nca_request_log_t) + \
1707c478bd9Sstevel@tonic-gate 					(p->name))
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate /* write data as offsets at end of nca_request_log_t buf */
1737c478bd9Sstevel@tonic-gate #define	NCA_REQLOG_WDATA(val, p, n_used, len, off) {	\
1747c478bd9Sstevel@tonic-gate 	if (!(val)) {					\
1757c478bd9Sstevel@tonic-gate 		p->len = 0;				\
1767c478bd9Sstevel@tonic-gate 		p->off = 0;				\
1777c478bd9Sstevel@tonic-gate 	} else {					\
1787c478bd9Sstevel@tonic-gate 		p->len = strlen(val) + 1;		\
1797c478bd9Sstevel@tonic-gate 		bcopy(val, ((char *)p + sizeof (nca_request_log_t) \
1807c478bd9Sstevel@tonic-gate 				+ n_used), (p->len));	\
1817c478bd9Sstevel@tonic-gate 		p->off = n_used;			\
1827c478bd9Sstevel@tonic-gate 		n_used += (p->len);			\
1837c478bd9Sstevel@tonic-gate 		}					\
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate #endif
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate #endif /* _INET_NCALOGD_H */
191