xref: /illumos-gate/usr/src/uts/common/sys/acctctl.h (revision da14cebe)
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*da14cebeSEric Cheng  * Common Development and Distribution License (the "License").
6*da14cebeSEric Cheng  * 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*da14cebeSEric Cheng  * Copyright 2008 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 _SYS_ACCTCTL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_ACCTCTL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/bitmap.h>
317c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * Definitions for acctctl() system call
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * modes
437c478bd9Sstevel@tonic-gate  */
44*da14cebeSEric Cheng #define	AC_PROC		(0x1 << 24)	/* change process accounting settings */
45*da14cebeSEric Cheng #define	AC_TASK		(0x2 << 24)	/* change task accounting settings */
46*da14cebeSEric Cheng #define	AC_FLOW		(0x4 << 24)	/* change flow accounting settings */
47*da14cebeSEric Cheng #define	AC_NET		(0x8 << 24)	/* change network accounting settings */
48*da14cebeSEric Cheng #define	AC_MODE(x)	((x) & 0xff000000)
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * options
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate #define	AC_FILE_SET	(0x01)	/* set accounting file name */
547c478bd9Sstevel@tonic-gate #define	AC_FILE_GET	(0x02)	/* get accounting file name */
557c478bd9Sstevel@tonic-gate #define	AC_RES_SET	(0x04)	/* set (enable/disable) resources */
567c478bd9Sstevel@tonic-gate #define	AC_RES_GET	(0x08)	/* get a list of enabled resources */
577c478bd9Sstevel@tonic-gate #define	AC_STATE_SET	(0x10)	/* set accounting mode state (on/off) */
587c478bd9Sstevel@tonic-gate #define	AC_STATE_GET	(0x20)	/* get accounting mode state */
59*da14cebeSEric Cheng #define	AC_OPTION(x)	((x) & 0x00ffffff)
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * Process accounting resource IDs
637c478bd9Sstevel@tonic-gate  */
647c478bd9Sstevel@tonic-gate #define	AC_NONE			0	/* special end-of-list identifier */
657c478bd9Sstevel@tonic-gate #define	AC_PROC_PID		1	/* process ID */
667c478bd9Sstevel@tonic-gate #define	AC_PROC_UID		2	/* user ID */
677c478bd9Sstevel@tonic-gate #define	AC_PROC_GID		3	/* group ID */
687c478bd9Sstevel@tonic-gate #define	AC_PROC_PROJID		4	/* project ID */
697c478bd9Sstevel@tonic-gate #define	AC_PROC_TASKID		5	/* task ID */
707c478bd9Sstevel@tonic-gate #define	AC_PROC_CPU		6	/* user/system cpu time */
717c478bd9Sstevel@tonic-gate #define	AC_PROC_TIME		7	/* start/finish time */
727c478bd9Sstevel@tonic-gate #define	AC_PROC_COMMAND		8	/* command name */
737c478bd9Sstevel@tonic-gate #define	AC_PROC_TTY		9	/* control tty */
747c478bd9Sstevel@tonic-gate #define	AC_PROC_HOSTNAME	10	/* hostname */
757c478bd9Sstevel@tonic-gate #define	AC_PROC_MICROSTATE	11	/* microstate accounting */
767c478bd9Sstevel@tonic-gate #define	AC_PROC_FLAG		12	/* accounting flags */
777c478bd9Sstevel@tonic-gate #define	AC_PROC_ANCPID		13	/* ancestor process's ID */
787c478bd9Sstevel@tonic-gate #define	AC_PROC_WAIT_STATUS	14	/* process wait status */
797c478bd9Sstevel@tonic-gate #define	AC_PROC_ZONENAME	15	/* zone name */
807c478bd9Sstevel@tonic-gate #define	AC_PROC_MEM		16	/* memory usage */
817c478bd9Sstevel@tonic-gate #define	AC_PROC_MAX_RES		16	/* must be equal to the number above */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * Task accounting resource IDs
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate #define	AC_TASK_TASKID		1	/* task ID */
877c478bd9Sstevel@tonic-gate #define	AC_TASK_PROJID		2	/* project ID */
887c478bd9Sstevel@tonic-gate #define	AC_TASK_CPU		3	/* user/system cpu time */
897c478bd9Sstevel@tonic-gate #define	AC_TASK_TIME		4	/* start/finish time */
907c478bd9Sstevel@tonic-gate #define	AC_TASK_HOSTNAME	5	/* hostname */
917c478bd9Sstevel@tonic-gate #define	AC_TASK_MICROSTATE	6	/* microstate accounting */
927c478bd9Sstevel@tonic-gate #define	AC_TASK_ANCTASKID	7	/* ancestor task's taskid */
937c478bd9Sstevel@tonic-gate #define	AC_TASK_ZONENAME	8	/* zone name */
947c478bd9Sstevel@tonic-gate #define	AC_TASK_MAX_RES		8	/* must be equal to the number above */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Flow accounting resource IDs
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate #define	AC_FLOW_SADDR		1	/* source address */
1007c478bd9Sstevel@tonic-gate #define	AC_FLOW_DADDR		2	/* destination address */
1017c478bd9Sstevel@tonic-gate #define	AC_FLOW_SPORT		3	/* source port */
1027c478bd9Sstevel@tonic-gate #define	AC_FLOW_DPORT		4	/* destination port */
1037c478bd9Sstevel@tonic-gate #define	AC_FLOW_PROTOCOL	5	/* protocol */
1047c478bd9Sstevel@tonic-gate #define	AC_FLOW_DSFIELD		6	/* dsfield */
1057c478bd9Sstevel@tonic-gate #define	AC_FLOW_CTIME		7	/* creation time for this flow */
1067c478bd9Sstevel@tonic-gate #define	AC_FLOW_LSEEN		8	/* pkt last seen for this flow */
1077c478bd9Sstevel@tonic-gate #define	AC_FLOW_NBYTES		9	/* no. of bytes in this flow */
1087c478bd9Sstevel@tonic-gate #define	AC_FLOW_NPKTS		10	/* no. of packets for this flow */
1097c478bd9Sstevel@tonic-gate #define	AC_FLOW_PROJID		11	/* project id */
1107c478bd9Sstevel@tonic-gate #define	AC_FLOW_UID		12	/* user id */
1117c478bd9Sstevel@tonic-gate #define	AC_FLOW_ANAME		13	/* action instance name */
1127c478bd9Sstevel@tonic-gate #define	AC_FLOW_MAX_RES		13	/* must be equal to the number above */
1137c478bd9Sstevel@tonic-gate 
114*da14cebeSEric Cheng /*
115*da14cebeSEric Cheng  * Network accounting resource IDs
116*da14cebeSEric Cheng  */
117*da14cebeSEric Cheng #define	AC_NET_NAME		1	/* flow name */
118*da14cebeSEric Cheng #define	AC_NET_EHOST		2	/* ethernet source address */
119*da14cebeSEric Cheng #define	AC_NET_EDEST		3	/* ethernet destination address */
120*da14cebeSEric Cheng #define	AC_NET_VLAN_TPID	4	/* VLAN protocol ID */
121*da14cebeSEric Cheng #define	AC_NET_VLAN_TCI		5	/* VLAN tag control info. */
122*da14cebeSEric Cheng #define	AC_NET_SAP		6	/* SAP */
123*da14cebeSEric Cheng #define	AC_NET_PRIORITY		7	/* Priority */
124*da14cebeSEric Cheng #define	AC_NET_BWLIMIT		8	/* Bandwidth limit */
125*da14cebeSEric Cheng #define	AC_NET_DEVNAME		9	/* Device name */
126*da14cebeSEric Cheng #define	AC_NET_SADDR		10	/* Source IP address */
127*da14cebeSEric Cheng #define	AC_NET_DADDR		11	/* Dest IP address */
128*da14cebeSEric Cheng #define	AC_NET_SPORT		12	/* Source Port */
129*da14cebeSEric Cheng #define	AC_NET_DPORT		13	/* Dest Port */
130*da14cebeSEric Cheng #define	AC_NET_PROTOCOL		14	/* Protocol */
131*da14cebeSEric Cheng #define	AC_NET_DSFIELD		15	/* DiffServ field */
132*da14cebeSEric Cheng #define	AC_NET_CURTIME		16	/* Current Time */
133*da14cebeSEric Cheng #define	AC_NET_IBYTES		17	/* Inbound Bytes */
134*da14cebeSEric Cheng #define	AC_NET_OBYTES		18	/* Outbound Bytes */
135*da14cebeSEric Cheng #define	AC_NET_IPKTS		19	/* Inbound Packets */
136*da14cebeSEric Cheng #define	AC_NET_OPKTS		20	/* Outbound Packets */
137*da14cebeSEric Cheng #define	AC_NET_IERRPKTS		21	/* Inbound Error Packets */
138*da14cebeSEric Cheng #define	AC_NET_OERRPKTS		22	/* Outbound Error Packets */
139*da14cebeSEric Cheng #define	AC_NET_MAX_RES		22	/* must be equal to the number above */
140*da14cebeSEric Cheng 
141*da14cebeSEric Cheng #define	AC_MAX_RES		\
142*da14cebeSEric Cheng 	MAX(MAX(MAX(AC_PROC_MAX_RES, AC_TASK_MAX_RES), AC_FLOW_MAX_RES), \
143*da14cebeSEric Cheng 	AC_NET_MAX_RES)
1447c478bd9Sstevel@tonic-gate #define	AC_MASK_SZ		BT_BITOUL(AC_MAX_RES + 1)
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate /*
1477c478bd9Sstevel@tonic-gate  * resource states
1487c478bd9Sstevel@tonic-gate  */
1497c478bd9Sstevel@tonic-gate #define	AC_ON		1	/* enabled resource */
1507c478bd9Sstevel@tonic-gate #define	AC_OFF		0	/* disabled resource */
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate typedef struct ac_res {
1537c478bd9Sstevel@tonic-gate 	int	ar_id;		/* resource ID */
1547c478bd9Sstevel@tonic-gate 	int	ar_state;	/* resource state; see above */
1557c478bd9Sstevel@tonic-gate } ac_res_t;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
1607c478bd9Sstevel@tonic-gate #include <sys/zone.h>
1617c478bd9Sstevel@tonic-gate #include <sys/list.h>
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate typedef struct ac_info {
1647c478bd9Sstevel@tonic-gate 	kmutex_t	ac_lock;		/* protects the structure */
1657c478bd9Sstevel@tonic-gate 	vnode_t		*ac_vnode;		/* exacct file vnode pointer */
1667c478bd9Sstevel@tonic-gate 	char		*ac_file;		/* exacct file name */
1677c478bd9Sstevel@tonic-gate 	int		ac_state;		/* accounting state */
1687c478bd9Sstevel@tonic-gate 	ulong_t		ac_mask[AC_MASK_SZ];	/* bitmask of resources */
1697c478bd9Sstevel@tonic-gate } ac_info_t;
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate /*
1727c478bd9Sstevel@tonic-gate  * Key used for retrieving per-zone exacct settings.  This remains
1737c478bd9Sstevel@tonic-gate  * uninitialized (ZONE_KEY_UNINITIALIZED) until the acctctl module is loaded.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate extern zone_key_t exacct_zone_key;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate  * Per-zone exacct settings.  Each zone may have its own settings for
179*da14cebeSEric Cheng  * process, task, flow, and network accounting.
1807c478bd9Sstevel@tonic-gate  *
1817c478bd9Sstevel@tonic-gate  * Per-zone flow accounting has not yet been implemented, so this
1827c478bd9Sstevel@tonic-gate  * provides zones with the view that flow accounting in the zone hasn't
1837c478bd9Sstevel@tonic-gate  * been initialized (which is true).  The various system calls will fail
1847c478bd9Sstevel@tonic-gate  * to set flow accounting parameters from within a zone.
1857c478bd9Sstevel@tonic-gate  *
1867c478bd9Sstevel@tonic-gate  * The global list of accounting settings is used when we check to see
1877c478bd9Sstevel@tonic-gate  * if the accounting file is already in use by any zone.
1887c478bd9Sstevel@tonic-gate  */
1897c478bd9Sstevel@tonic-gate struct exacct_globals {
1907c478bd9Sstevel@tonic-gate 	ac_info_t	ac_task;
1917c478bd9Sstevel@tonic-gate 	ac_info_t	ac_proc;
1927c478bd9Sstevel@tonic-gate 	ac_info_t	ac_flow;
193*da14cebeSEric Cheng 	ac_info_t	ac_net;
1947c478bd9Sstevel@tonic-gate 	list_node_t	ac_link;
1957c478bd9Sstevel@tonic-gate };
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate #else
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate extern int acctctl(int cmd, void *buf, size_t bufsz);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate #endif	/* ifdef _KERNEL */
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate #endif
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate #endif	/* _SYS_ACCTCTL_H */
208