xref: /onnv-gate/usr/src/uts/common/sys/acctctl.h (revision 8275:7c223a798022)
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*8275SEric Cheng  * Common Development and Distribution License (the "License").
6*8275SEric Cheng  * 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*8275SEric Cheng  * Copyright 2008 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 _SYS_ACCTCTL_H
270Sstevel@tonic-gate #define	_SYS_ACCTCTL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/bitmap.h>
310Sstevel@tonic-gate #include <sys/sysmacros.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #ifdef	__cplusplus
340Sstevel@tonic-gate extern "C" {
350Sstevel@tonic-gate #endif
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate  * Definitions for acctctl() system call
390Sstevel@tonic-gate  */
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * modes
430Sstevel@tonic-gate  */
44*8275SEric Cheng #define	AC_PROC		(0x1 << 24)	/* change process accounting settings */
45*8275SEric Cheng #define	AC_TASK		(0x2 << 24)	/* change task accounting settings */
46*8275SEric Cheng #define	AC_FLOW		(0x4 << 24)	/* change flow accounting settings */
47*8275SEric Cheng #define	AC_NET		(0x8 << 24)	/* change network accounting settings */
48*8275SEric Cheng #define	AC_MODE(x)	((x) & 0xff000000)
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * options
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate #define	AC_FILE_SET	(0x01)	/* set accounting file name */
540Sstevel@tonic-gate #define	AC_FILE_GET	(0x02)	/* get accounting file name */
550Sstevel@tonic-gate #define	AC_RES_SET	(0x04)	/* set (enable/disable) resources */
560Sstevel@tonic-gate #define	AC_RES_GET	(0x08)	/* get a list of enabled resources */
570Sstevel@tonic-gate #define	AC_STATE_SET	(0x10)	/* set accounting mode state (on/off) */
580Sstevel@tonic-gate #define	AC_STATE_GET	(0x20)	/* get accounting mode state */
59*8275SEric Cheng #define	AC_OPTION(x)	((x) & 0x00ffffff)
600Sstevel@tonic-gate 
610Sstevel@tonic-gate /*
620Sstevel@tonic-gate  * Process accounting resource IDs
630Sstevel@tonic-gate  */
640Sstevel@tonic-gate #define	AC_NONE			0	/* special end-of-list identifier */
650Sstevel@tonic-gate #define	AC_PROC_PID		1	/* process ID */
660Sstevel@tonic-gate #define	AC_PROC_UID		2	/* user ID */
670Sstevel@tonic-gate #define	AC_PROC_GID		3	/* group ID */
680Sstevel@tonic-gate #define	AC_PROC_PROJID		4	/* project ID */
690Sstevel@tonic-gate #define	AC_PROC_TASKID		5	/* task ID */
700Sstevel@tonic-gate #define	AC_PROC_CPU		6	/* user/system cpu time */
710Sstevel@tonic-gate #define	AC_PROC_TIME		7	/* start/finish time */
720Sstevel@tonic-gate #define	AC_PROC_COMMAND		8	/* command name */
730Sstevel@tonic-gate #define	AC_PROC_TTY		9	/* control tty */
740Sstevel@tonic-gate #define	AC_PROC_HOSTNAME	10	/* hostname */
750Sstevel@tonic-gate #define	AC_PROC_MICROSTATE	11	/* microstate accounting */
760Sstevel@tonic-gate #define	AC_PROC_FLAG		12	/* accounting flags */
770Sstevel@tonic-gate #define	AC_PROC_ANCPID		13	/* ancestor process's ID */
780Sstevel@tonic-gate #define	AC_PROC_WAIT_STATUS	14	/* process wait status */
790Sstevel@tonic-gate #define	AC_PROC_ZONENAME	15	/* zone name */
800Sstevel@tonic-gate #define	AC_PROC_MEM		16	/* memory usage */
810Sstevel@tonic-gate #define	AC_PROC_MAX_RES		16	/* must be equal to the number above */
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate  * Task accounting resource IDs
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate #define	AC_TASK_TASKID		1	/* task ID */
870Sstevel@tonic-gate #define	AC_TASK_PROJID		2	/* project ID */
880Sstevel@tonic-gate #define	AC_TASK_CPU		3	/* user/system cpu time */
890Sstevel@tonic-gate #define	AC_TASK_TIME		4	/* start/finish time */
900Sstevel@tonic-gate #define	AC_TASK_HOSTNAME	5	/* hostname */
910Sstevel@tonic-gate #define	AC_TASK_MICROSTATE	6	/* microstate accounting */
920Sstevel@tonic-gate #define	AC_TASK_ANCTASKID	7	/* ancestor task's taskid */
930Sstevel@tonic-gate #define	AC_TASK_ZONENAME	8	/* zone name */
940Sstevel@tonic-gate #define	AC_TASK_MAX_RES		8	/* must be equal to the number above */
950Sstevel@tonic-gate 
960Sstevel@tonic-gate /*
970Sstevel@tonic-gate  * Flow accounting resource IDs
980Sstevel@tonic-gate  */
990Sstevel@tonic-gate #define	AC_FLOW_SADDR		1	/* source address */
1000Sstevel@tonic-gate #define	AC_FLOW_DADDR		2	/* destination address */
1010Sstevel@tonic-gate #define	AC_FLOW_SPORT		3	/* source port */
1020Sstevel@tonic-gate #define	AC_FLOW_DPORT		4	/* destination port */
1030Sstevel@tonic-gate #define	AC_FLOW_PROTOCOL	5	/* protocol */
1040Sstevel@tonic-gate #define	AC_FLOW_DSFIELD		6	/* dsfield */
1050Sstevel@tonic-gate #define	AC_FLOW_CTIME		7	/* creation time for this flow */
1060Sstevel@tonic-gate #define	AC_FLOW_LSEEN		8	/* pkt last seen for this flow */
1070Sstevel@tonic-gate #define	AC_FLOW_NBYTES		9	/* no. of bytes in this flow */
1080Sstevel@tonic-gate #define	AC_FLOW_NPKTS		10	/* no. of packets for this flow */
1090Sstevel@tonic-gate #define	AC_FLOW_PROJID		11	/* project id */
1100Sstevel@tonic-gate #define	AC_FLOW_UID		12	/* user id */
1110Sstevel@tonic-gate #define	AC_FLOW_ANAME		13	/* action instance name */
1120Sstevel@tonic-gate #define	AC_FLOW_MAX_RES		13	/* must be equal to the number above */
1130Sstevel@tonic-gate 
114*8275SEric Cheng /*
115*8275SEric Cheng  * Network accounting resource IDs
116*8275SEric Cheng  */
117*8275SEric Cheng #define	AC_NET_NAME		1	/* flow name */
118*8275SEric Cheng #define	AC_NET_EHOST		2	/* ethernet source address */
119*8275SEric Cheng #define	AC_NET_EDEST		3	/* ethernet destination address */
120*8275SEric Cheng #define	AC_NET_VLAN_TPID	4	/* VLAN protocol ID */
121*8275SEric Cheng #define	AC_NET_VLAN_TCI		5	/* VLAN tag control info. */
122*8275SEric Cheng #define	AC_NET_SAP		6	/* SAP */
123*8275SEric Cheng #define	AC_NET_PRIORITY		7	/* Priority */
124*8275SEric Cheng #define	AC_NET_BWLIMIT		8	/* Bandwidth limit */
125*8275SEric Cheng #define	AC_NET_DEVNAME		9	/* Device name */
126*8275SEric Cheng #define	AC_NET_SADDR		10	/* Source IP address */
127*8275SEric Cheng #define	AC_NET_DADDR		11	/* Dest IP address */
128*8275SEric Cheng #define	AC_NET_SPORT		12	/* Source Port */
129*8275SEric Cheng #define	AC_NET_DPORT		13	/* Dest Port */
130*8275SEric Cheng #define	AC_NET_PROTOCOL		14	/* Protocol */
131*8275SEric Cheng #define	AC_NET_DSFIELD		15	/* DiffServ field */
132*8275SEric Cheng #define	AC_NET_CURTIME		16	/* Current Time */
133*8275SEric Cheng #define	AC_NET_IBYTES		17	/* Inbound Bytes */
134*8275SEric Cheng #define	AC_NET_OBYTES		18	/* Outbound Bytes */
135*8275SEric Cheng #define	AC_NET_IPKTS		19	/* Inbound Packets */
136*8275SEric Cheng #define	AC_NET_OPKTS		20	/* Outbound Packets */
137*8275SEric Cheng #define	AC_NET_IERRPKTS		21	/* Inbound Error Packets */
138*8275SEric Cheng #define	AC_NET_OERRPKTS		22	/* Outbound Error Packets */
139*8275SEric Cheng #define	AC_NET_MAX_RES		22	/* must be equal to the number above */
140*8275SEric Cheng 
141*8275SEric Cheng #define	AC_MAX_RES		\
142*8275SEric Cheng 	MAX(MAX(MAX(AC_PROC_MAX_RES, AC_TASK_MAX_RES), AC_FLOW_MAX_RES), \
143*8275SEric Cheng 	AC_NET_MAX_RES)
1440Sstevel@tonic-gate #define	AC_MASK_SZ		BT_BITOUL(AC_MAX_RES + 1)
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate  * resource states
1480Sstevel@tonic-gate  */
1490Sstevel@tonic-gate #define	AC_ON		1	/* enabled resource */
1500Sstevel@tonic-gate #define	AC_OFF		0	/* disabled resource */
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate typedef struct ac_res {
1530Sstevel@tonic-gate 	int	ar_id;		/* resource ID */
1540Sstevel@tonic-gate 	int	ar_state;	/* resource state; see above */
1550Sstevel@tonic-gate } ac_res_t;
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate #ifdef	_KERNEL
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate #include <sys/vnode.h>
1600Sstevel@tonic-gate #include <sys/zone.h>
1610Sstevel@tonic-gate #include <sys/list.h>
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate typedef struct ac_info {
1640Sstevel@tonic-gate 	kmutex_t	ac_lock;		/* protects the structure */
1650Sstevel@tonic-gate 	vnode_t		*ac_vnode;		/* exacct file vnode pointer */
1660Sstevel@tonic-gate 	char		*ac_file;		/* exacct file name */
1670Sstevel@tonic-gate 	int		ac_state;		/* accounting state */
1680Sstevel@tonic-gate 	ulong_t		ac_mask[AC_MASK_SZ];	/* bitmask of resources */
1690Sstevel@tonic-gate } ac_info_t;
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate  * Key used for retrieving per-zone exacct settings.  This remains
1730Sstevel@tonic-gate  * uninitialized (ZONE_KEY_UNINITIALIZED) until the acctctl module is loaded.
1740Sstevel@tonic-gate  */
1750Sstevel@tonic-gate extern zone_key_t exacct_zone_key;
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate /*
1780Sstevel@tonic-gate  * Per-zone exacct settings.  Each zone may have its own settings for
179*8275SEric Cheng  * process, task, flow, and network accounting.
1800Sstevel@tonic-gate  *
1810Sstevel@tonic-gate  * Per-zone flow accounting has not yet been implemented, so this
1820Sstevel@tonic-gate  * provides zones with the view that flow accounting in the zone hasn't
1830Sstevel@tonic-gate  * been initialized (which is true).  The various system calls will fail
1840Sstevel@tonic-gate  * to set flow accounting parameters from within a zone.
1850Sstevel@tonic-gate  *
1860Sstevel@tonic-gate  * The global list of accounting settings is used when we check to see
1870Sstevel@tonic-gate  * if the accounting file is already in use by any zone.
1880Sstevel@tonic-gate  */
1890Sstevel@tonic-gate struct exacct_globals {
1900Sstevel@tonic-gate 	ac_info_t	ac_task;
1910Sstevel@tonic-gate 	ac_info_t	ac_proc;
1920Sstevel@tonic-gate 	ac_info_t	ac_flow;
193*8275SEric Cheng 	ac_info_t	ac_net;
1940Sstevel@tonic-gate 	list_node_t	ac_link;
1950Sstevel@tonic-gate };
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate #else
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate extern int acctctl(int cmd, void *buf, size_t bufsz);
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate #endif	/* ifdef _KERNEL */
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate #ifdef	__cplusplus
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate #endif
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate #endif	/* _SYS_ACCTCTL_H */
208